def main
arr = [1,-41,33,4,5,33,4,2,-41,10]
n = arr.length
start = -1
lmax = -1
for i in 0..n-1
start = i
j = n - 1
while j >= 0 and arr[i] != arr[j]
j -= 1
end
if j - start > lmax
lmax = j - start
lstart = start
end
end
print arr
print"\nOutput:\n"
print"Start position: ", lstart
print "\nSubsequence is: "
for i in lstart..lstart+lmax
print arr[i]," "
end
print "\nLength: ", lmax, "\n"
end
main
ZGVmIG1haW4KICAgIGFyciA9IFsxLC00MSwzMyw0LDUsMzMsNCwyLC00MSwxMF0KICAgIG4gPSBhcnIubGVuZ3RoCiAgICBzdGFydCA9IC0xCiAgICBsbWF4ID0gIC0xCiAgICBmb3IgaSBpbiAwLi5uLTEKICAgICAgICBzdGFydCA9IGkKICAgICAgICBqID0gbiAtIDEKICAgICAgICB3aGlsZSBqID49IDAgYW5kIGFycltpXSAhPSBhcnJbal0KICAgICAgICAgICAgaiAtPSAxCiAgICAgICAgZW5kCiAgICAgICAgaWYgaiAtIHN0YXJ0ID4gbG1heAogICAgICAgICAgbG1heCA9IGogLSBzdGFydAogICAgICAgICAgbHN0YXJ0ID0gc3RhcnQKICAgICAgICBlbmQKICAgIGVuZAogICAgcHJpbnQgYXJyCiAgICBwcmludCJcbk91dHB1dDpcbiIKICAgIHByaW50IlN0YXJ0IHBvc2l0aW9uOiAiLCBsc3RhcnQKICAgIHByaW50ICJcblN1YnNlcXVlbmNlIGlzOiAiCiAgICBmb3IgaSBpbiBsc3RhcnQuLmxzdGFydCtsbWF4CiAgICAgIHByaW50IGFycltpXSwiICIKICAgIGVuZAogICAgcHJpbnQgIlxuTGVuZ3RoOiAiLCBsbWF4LCAiXG4iCmVuZAoKbWFpbgo=
[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