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
1d

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...
Auzmor Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter