Pascal triangle digit encryption
Digits are encrypted by folding them down an upside-down Pascal's triangle.
You get a list of n digits (each 0-9). In one round, replace the list with the sums of each pair of neighbours, keeping only the last digit of each sum ((a + b) % 10). The list gets one shorter each round. Stop when exactly two digits remain.
Implement:
def encrypt(digits: list[int]) -> str
Return the final two digits as a two-character string. Keep a leading zero ("07", not "7").
Constraints
-
2 <= n <= 1000(a follow-up raises this to10^5) - every element is between
0and9
Example 1
digits = [1, 2, 3, 4]
round 1: [3, 5, 7]
round 2: [8, 2]
output: "82"
Example 2
digits = [0, 7]
already two digits
output: "07"
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
