Leetcode 1755 Solution
This article provides solution to leetcode question 1755 (defuse-the-bomb)
Access this page by simply typing in "lcs 1755" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/defuse-the-bomb
Solution
class Solution:
def decrypt(self, code: List[int], k: int) -> List[int]:
prefix = 0
prefix_arr = []
for num in code + code:
prefix += num
prefix_arr.append(prefix)
ans = []
for i in range(len(code)):
if k == 0:
ans.append(0)
elif k > 0:
ans.append(prefix_arr[i + k] - prefix_arr[i])
elif k < 0:
ans.append(prefix_arr[len(code) + i - 1] - prefix_arr[len(code) + i - 1 + k])
return ans