fork download
  1. def main
  2. arr = [1,-41,33,4,5,33,4,2,-41,10]
  3. n = arr.length
  4. start = -1
  5. lmax = -1
  6. for i in 0..n-1
  7. start = i
  8. j = n - 1
  9. while j >= 0 and arr[i] != arr[j]
  10. j -= 1
  11. end
  12. if j - start > lmax
  13. lmax = j - start
  14. lstart = start
  15. end
  16. end
  17. print arr
  18. print"\nOutput:\n"
  19. print"Start position: ", lstart
  20. print "\nSubsequence is: "
  21. for i in lstart..lstart+lmax
  22. print arr[i]," "
  23. end
  24. print "\nLength: ", lmax, "\n"
  25. end
  26.  
  27. main
  28.  
Success #stdin #stdout 0.01s 6272KB
stdin
Standard input is empty
stdout
[1, -41, 33, 4, 5, 33, 4, 2, -41, 10]
Output:
Start position: 1
Subsequence is: -41 33 4 5 33 4 2 -41 
Length: 7