All Problems

Problem title

Difficulty

Avg time to solve

Bob’s Path Task!

Easy

15 mins

Postorder Successor

Moderate

15 mins

K - Sum Path In A Binary Tree

Moderate

35 mins

K Turns Allowed

Moderate

25 mins

Special Sum of Array

Easy

15 mins

Interesting Alphabets

Easy

10 mins

Chocolate Fest

Moderate

25 mins

Ninja and power of 2

Easy

15 mins

Starfield

Easy

15 mins

Play with Pattern

Easy

20 mins

Problem

Submissions

6

Avg. time to solve

15 min

Success Rate

80%

Problem Statement

```
For the given array [5, 8, 4, 9]
The sum of the elements of the array will be
5 + 8 + 4 + 9 = 26.
Since 26 is not a single-digit number, we will again take the sum of the digits of 26.
2 + 6 = 8.
Now 8 is a single-digit number. So we will stop here and return 8.
```

```
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains a single integer ‘N’, representing the size of the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the given array.
```

```
For each test case, print a single-digit integer representing the sum of the array.
Output for each test case will be printed in a separate line.
```

```
You are not required to print anything, it has already been taken care of. Just implement the function.
```

```
1 <= T <= 100
1 <= N <= 10^3
0 <= arr[i] <= 9
It is guaranteed that the sum of ‘N’ over all test cases doesn’t exceed 10^5.
Time Limit: 1 sec.
```

```
2
5
8 7 0 1 2
4
4 2 1 1
```

```
9
8
```

```
Test Case 1:
For the given array [8, 7, 0, 1, 2]
The sum of the elements of the array will be
8 + 7 + 0 + 1 + 2 = 18.
Since 18 is not a single-digit number, we will again take the sum of the digits of 18.
1 + 8 = 9.
Now 9 is a single-digit number. So we will stop here and return 9.
Test Case 2:
For the given array [4, 2, 1, 1]
The sum of the elements of the array will be
4 + 2+ 1 + 1 = 8.
Since 8 is a single-digit number, we will just return 8.
```

```
2
4
3 1 2 1
9
1 9 4 6 2 8 2 0 1
```

```
7
6
```

Java (SE 1.8)

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Theme

Solution submission not allowed

Save Code

Reset Code