cswork / OAOpen practice workspace

AccentureOA #1

Smallest Number Greater Than K

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)EnumerationStrings

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);

Example 1

Input:

numStr = "7195"
k = 16

Output:

"19"

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

Example 2

Input:

numStr = "7195"
k = 14

Output:

"15"

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

Editorial

Loading solution…