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
Be the first one to answer
Add answer anonymously...
Top Walmart Senior Software Engineer interview questions & answers
Popular interview questions of Senior Software Engineer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app