Statistics

Problem Statement for "NumList"

Problem Statement

PROBLEM STATEMENT:

Given positive integers n and k, return the kth integer in the lexically
ordered list of integers 1 through n inclusive.

e.g. The integers 1 through 15 ordered lexically are:

1,10,11,12,13,14,15,2,3,4,5,6,7,8,9

e.g. The integers 1 through 123 ordered lexically are:

1,10,100,101,...,122,123,13,14,...,98,99

DEFINITION:

Class: NumList
Method: getKth
Parameters: int,int
Returns: int
Method Signature (be sure your method is public): int getKth(int n, int k);

TOPCODER WILL ENSURE:
 * 1 <= n <= 100000000
 * 1 <= k <= n

NOTES:
* The index k is a one-based index.  k=1 refers to the first integer in the
list.  k=n refers to the last integer in the list.
* lexical ordering is also known as alphabetical ordering or dictionary
ordering.  It's the ordering induced by comparing integers as strings.

EXAMPLES:

1.  n=15
    k=1
    getKth returns 1

2.  n=15
    k=8
    getKth returns 2

3.  n=15
    k=15
    getKth returns 9

4.  n=123
    k=3
    getKth returns 100

5.  n=123
    k=123
    getKth returns 99

6.  n=8293
    k=1234
    getKth returns 2108

Definition

Class:
NumList
Method:
getKth
Parameters:
int, int
Returns:
int
Method signature:
int getKth(int param0, int param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: