FastPrepFastPrep
Problem Brief

Smallest Number Greater Than K

OA

You are given an integer n and a threshold integer k. Your task is to form the smallest number possible from the digits of n by deleting some digits, while maintaining the original order of the digits. The formed number must be greater than k.

Details:

  • You must preserve the order of the digits from n.
  • If the smallest number you can form is less than or equal to k, try to include additional digits from n to ensure the result is greater than k.
  • Function Signature:

    string smallestNumberGreaterThanK(string numStr, int k);

    1Example 1

    Input
    numStr = "7195", k = 16
    Output
    "19"
    Explanation

    For n = 7195 and k = 16, the output should be 19.

    2Example 2

    Input
    numStr = "7195", k = 14
    Output
    "15"
    Explanation

    For n = 7195 and k = 14, the output should be 15.

    Constraints

    Limits and guarantees your solution can rely on.

    🥑🥑
    public String smallestNumberGreaterThanK(String numStr, int k) {
      // write your code here
    }
    
    Input

    numStr

    "7195"

    k

    16

    Output

    "19"

    Sign in to submit your solution.