Hello
i’m trying to iterate through a circular list and add the next x values but i need some help
from typing import List
def solution(k: [int], x: int) → [int]:
res =
n = len(k)
for i in range(len(k)):
if x > 0:
j = k[(i + 1) % len(k)] + k[(i + x) % len(k)] # sum of the next x values
elif x < 0:
j = sum(k[(i+x):i]) # sum of the previous x values
else:
j = 0 # x is zero
res.append(j)
return res
if i call solutions with;
solution([1,2,3,4], 2) it works properly,but if call solutions with the x value greater than 2 it won’t work well, i need some help reconstructing the j formular so that my output is the sum of the next x values