Sum of Digits Problem Statement

Given an integer 'N', continue summing its digits until the result is a single-digit number. Your task is to determine the final value of 'N' after applying this operation iteratively until the value is less than 10.

Input:

The first line contains an integer 'T' which represents the number of test cases. Each test case consists of a single integer 'N' provided in a new line.

Output:

For each test case, output the final single-digit integer in a separate line.

Example:

Input:
2
38
1337
Output:
2
5
Explanation:

In the first test case, 38 -> 3 + 8 = 11 -> 1 + 1 = 2.

In the second test case, 1337 -> 1 + 3 + 3 + 7 = 14 -> 1 + 4 = 5.

Constraints:

  • 1 <= T <= 11
  • 1 <= N <= 109
  • Time Limit: 1 second
AnswerBot
4mo

Given an integer, find the final single-digit value after summing its digits iteratively.

  • Iteratively sum the digits of the input integer until the result is a single-digit number

  • Output the final singl...read more

Help your peers!
Select
Add answer anonymously...

Top Senior Software Engineer Interview Questions Asked at Walmart

Q. Explain Database models
Q. Describe the design and architecture of LinkedIn.
Q. Design and code a hashmap.
Senior Software Engineer 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