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, sum its digits until a single-digit number is obtained. Determine the final single-digit integer.

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

  • Outp...read more

Help your peers!
Select
Add answer anonymously...

Morgan Stanley Technology Analyst interview questions & answers

A Technology Analyst was asked Q. Explain the Bubble Sort algorithm.
A Technology Analyst was asked Q. Given a number, print it in words.
A Technology Analyst was asked Q. Flatten a Multilevel Sorted Linked List You are given a linked list with 'N' nod...read more

Popular interview questions of Technology Analyst

A Technology Analyst was asked Q1. Explain the Bubble Sort algorithm.
A Technology Analyst was asked Q2. Given a number, print it in words.
A Technology Analyst was asked Q3. Flatten a Multilevel Sorted Linked List You are given a linked list with 'N' nod...read more
Morgan Stanley Technology Analyst 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