Special Sum of Array Problem Statement

Given an array 'arr' containing single-digit integers, your task is to calculate the total sum of all its elements. However, the resulting sum must also be a single-digit number. To achieve this, repeatedly sum the digits of the result until a single-digit number is obtained.

Example:

Input:
[5, 8, 4, 9]
Output:
8
Explanation:

The sum of the elements is 26. The sum of the digits 2 + 6 = 8 is a single-digit number.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 10^3
  • 0 <= arr[i] <= 9
  • The sum of 'N' across all test cases does not exceed 10^5.

Time Limit: 1 sec.

AnswerBot
4mo

Calculate the total sum of array elements until a single-digit number is obtained by repeatedly summing digits.

  • Iterate through the array and calculate the sum of all elements.

  • If the sum is a single-di...read more

Anonymous
5mo
def num(n): if n &lt; = 9 : return n while len(str(n)) > 1: string=str(n) sum=0 for i in range(len(string)): sum=sum+int(string[i]) if len(str(sum))==1: return sum else: return num(sum)
Help your peers!
Select
Add answer anonymously...

Top Data Scientist Interview Questions Asked at Bajaj Finserv

Q. What detailed questions do you have about machine learning models?
Q. What is cross validation?
Q. With 2 dependent and 6 independent variables available, which machine learning a...read more
Data Scientist 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