# Help me understand time complexity between two solutions

Can you help me realize the difference between my code ( time exceed error) and an accepted solution by rekhansh99 [24043418] ( just for credits

My solution:
https://www.codechef.com/viewsolution/24043314

Accepted Solution:
https://www.codechef.com/viewsolution/24043418

i guess the accepted solution has 3 loops and for my code time complexity for each case is O(n)
as calculation is done with respect to the input itself

(yes , i was unable to understand the possible solutions approach)

for my code the approach is

i make the first element as 0, and then the input comes in
like 0,1,2,1,2
now i will start from 1 to n
and a counter i will keep track of the position my user is at

so when a[1] =1 (is entered my i is still 0 )
j loop keeps on taking input
untill j == i+k ( if i+k is encountered we compare i+1 and i+k)
and which ever one is smaller i will shift to it and sum will be added to a sum variable

Can you help me clear my doubts or optimize my approach, and possibly help me why i am getting time exceeded error

Problem is with your variable i, which you have initially looped from 0 to cases-1, but inside of it, you are changing itâ€™s value to 0, thus, the test cases loop runs infinitely.

Thx a lot ,sir.
sorry for wasting your time for a silly thing.
My expression: -__-