Find the Greater Number with At Most One Non-Zero Digit
Explanation:
Given a positive integer N
, determine the smallest number K
that is greater than N
and has at most one non-zero digit. The goal is to find such a K
where:
1. 'K' is strictly greater than 'N'.
2. 'K' contains at most one non-zero digit.
3. The difference between 'N' and 'K' is as small as possible.
Input:
The first line contains an integer 'T', the number of test cases.
Each test case has one line containing a positive integer 'N'.
Output:
For each test case, output a single integer 'K', the smallest number greater than 'N' with at most one non-zero digit.
Example:
Input:
1
546
Output:
600
Constraints:
1 <= T <= 1000
1 <= N <= 10^{18}
Time limit: 1 second

AnswerBot
4mo
Find the smallest number greater than N with at most one non-zero digit.
Iterate from N+1 until finding a number with at most one non-zero digit
Check if a number has at most one non-zero digit by count...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

