Ctrl K

Top of the Digit Pyramid

Medium
The bottom row of a pyramid holds the digits from the list digits. Each row above is one cell shorter: the cell sitting on two neighbours gets the last digit of their sum, that is (a + b) % 10. Rows keep being built until a single cell is left. Return the digit at the top of the pyramid.
Example 1
digits=[3, 8, 6] → 5

The second row is (3 + 8) % 10 = 1 and (8 + 6) % 10 = 4. The top is (1 + 4) % 10 = 5.

Example 2
digits=[9, 9, 9, 9] → 2

The rows go [8, 8, 8], then [6, 6], then [2], so the top is 2.

Example 3
digits=[7] → 7

A single digit is already the top.

Constraints
  • 1 ≤ len(digits) ≤ 1000
  • 0 ≤ digits[i] ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRunning Sum Waves MediumRiffle Shuffles Until the Deck Resets MediumLast One in the Circle MediumRestore the Lost Dice MediumPicks Without a Fixed Gap Medium
loading Python…
Input
digits=[3, 8, 6]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.