Oracle Logo

Asked in Oracle

Number and Digits Problem Statement

You are provided with a positive integer N. Your task is to identify all numbers such that the sum of the number and its digits equals N.

Example:

Input:
N = 21
Output:
[15]
Explanation:

The only number where the sum of the number and its digits equals 21 is 15, as 15 + 1 + 5 = 21.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^{12}
  • Time Limit: 1 sec

Input:

The first line contains a single integer ‘T’ representing the number of test cases.
Each test case consists of a single integer ‘N’, which represents the given integer.

Output:

For each test case, print all space-separated integers whose sum of digits with themselves is equal to ‘N’ in increasing order. Print -1 if no such integer exists.
Print a separate line for each test case.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
AnswerBot
4mo

Identify numbers whose sum with digits equals given integer N.

  • Iterate through numbers from 1 to N and check if sum of number and its digits equals N.

  • Use a helper function to calculate sum of digits fo...read more

Help your peers!
Select
Add answer anonymously...

Top Mts1 Interview Questions Asked at Oracle

Q. What is a singleton class?
Q. Check if a Number is Binary Determine if a given string of integers bin represen...read more
Q. What will be the result when adding two binary numbers in a 64-bit and a 32-bit ...read more
Mts1 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