
Asked in Bajaj Finserv
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 < = 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!
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
Interview Questions Asked to Data Scientist at Other Companies
Top Skill-Based Questions for Bajaj Finserv Data Scientist
Python Interview Questions and Answers
400 Questions
Machine Learning Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

