fork(15) download
  1.  
  2. # python3 code .
  3. def seq(arr):
  4. if len(arr) <= 2:
  5. return len(arr)
  6. else :
  7. ans = 2;
  8. tmp_ans = 2;
  9. for i in range(2 , len(arr)):
  10. if arr[i]==arr[i-2]:
  11. tmp_ans = tmp_ans + 1
  12. else :
  13. tmp_ans = 2
  14.  
  15. ans = max(ans , tmp_ans)
  16. return ans
  17.  
  18.  
  19. l = [7 , -5 , -5 , -5 , 7 , -1 , 7];
  20. print(seq(l))
Success #stdin #stdout 0.02s 9180KB
stdin
Standard input is empty
stdout
3