Find Triangular Sum of an Array

You are given a 0-indexed array nums of digits (0 to 9). Repeatedly replace nums with a new array one element shorter, where newNums[i] = (nums[i] + nums[i + 1]) % 10, until one element remains. Return that element, the triangular sum of nums.

30:00

Find Triangular Sum of an Array
medium
Free written solution
Topics
Companies

You are given a 0-indexed array nums of digits (0 to 9). Repeatedly replace nums with a new array one element shorter, where newNums[i] = (nums[i] + nums[i + 1]) % 10, until one element remains. Return that element, the triangular sum of nums.

Example 1:
Input: {"nums":[1,2,3,4,5]}
Output: 8
Constraints:
  • 1≤nums.length≤10001 \leq \text{nums.length} \leq 1000

  • 0≤nums[i]≤90 \leq \text{nums}[i] \leq 9

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,2,3,4,5]}

Row 0 is the input, 5 digits. Each new row is one shorter: every cell is (left parent + right parent) % 10.

the triangle, 5 digits on top

r0

1

2

3

4

5

Variables
VariableValue
n5
DepthFunction Call
Stack empty
0/16