TopcoderArchiveVisit Topcoder
SRM24 Mar 2009
SRM 437

TheInteger

Problem statement, definition, constraints, and public examples.

Problem Statement

There is nothing more beautiful than just an integer number.

You are given an integer n. Return the smallest integer greater than or equal to n that contains exactly k distinct digits in decimal notation.

Definition

Class:
TheInteger
Method:
find
Parameters:
long, int
Returns:
long
Method signature:
long find(long n, int k)
(be sure your method is public)

Constraints

  • n will be between 1 and 10^18, inclusive.
  • k will be between 1 and 10, inclusive.

Examples

  1. 47
    1
    Returns: 55
    Here, k is 1, so we're looking for a number whose digits are all equal. The smallest such number that is greater than or equal to 47 is 55.
  2. 7
    3
    Returns: 102
    We need three distinct digits here.
  3. 69
    2
    Returns: 69
    69 already consists of two different digits.
  4. 12364
    3
    Returns: 12411
Back to all problems