Indexing K sum
Problem to form the list for below sample inputs.
Example-1:
Input : n = [ 1, 2, 3, 4, 5] k = 3 Output : [1, 2, 3] [2, 3, 4] [3, 4, 5]
Example-2:
Input : n = [ 1, 2, 3, 4, 5] k = 4 Output : [1, 2, 3, 4] [2, 3, 4, 5]
Example-3:
Input : n = [ 1, 2, 3, 4] k = 2 Output : [1, 2] [2, 3] [3, 4]
Solution
n = [ 1, 2, 3, 4, 5] k = 3 for i in range(len(n)): if(len(n[i:i+k])==k): print(n[i:i+k])
Output
[1, 2, 3] [2, 3, 4] [3, 4, 5]