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
.
-
Input:
- An integer
n
(e.g., 7195). - An integer
k
(e.g., 16).
- An integer
-
Output:
- The smallest number formed from the digits of
n
such that the number is greater thank
. If no such number can be formed, output0
.
- The smallest number formed from the digits of
-
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 fromn
to ensure the result is greater thank
.
- You must preserve the order of the digits from
-
Example:
- For
n = 7195
andk = 16
, the output should be19
. - For
n = 7195
andk = 14
, the output should be15
.
- For
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.