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!
Select
Add answer anonymously...
Auzmor Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits