https://leetcode.com/problems/find-triangular-sum-of-an-array/
So I am solving this leetcode problem and have come up with the following solution
class Solution:
def triangularSum(self, nums: List[int]) -> int:
arrLen = len(nums)
newArr = []
while len(nums) != 2:
for i in range(0, arrLen - 1):
total = (nums[i] + nums[i + 1])
total %= 10
newArr.append(total)
nums = newArr
arrLen = len(nums)
newArr = []
res = nums[0] + nums[1]
return res
So It passes the test case, but when I press submit I get a Time Limit Exceeded error. The details say, 1 / 300 test cases passed. STATUS: Time Limit Exceeded.
Did I do something wrong with my algorithm? Or is there some way to make it faster? I am really lost