Panda Guru LogoPanda
Guru

Accenture OA Question 2025 | OA | MinimumGreatestNumberGreaterthenK can anyone solve this?

Round 1

Questions: 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.

  1. Input:

    • An integer n (e.g., 7195).
    • An integer k (e.g., 16).
  2. Output:

    • The smallest number formed from the digits of n such that the number is greater than k. If no such number can be formed, output 0.
  3. 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.
  4. Example:

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

Function Signature:

string smallestNumberGreaterThanK(string numStr, int k);

Example Usage:

int n = 7195; int k = 16; string numStr = to_string(n); string result = smallestNumberGreaterThanK(numStr, k); cout << "The smallest number formed is: " << result << endl; // Output: 19
Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.