def long_continuous_seq(A):
ls = {}
result = (0,0)
for x in A:
if not x in ls:
left = ls[x - 1] if (x - 1) in ls else 0
right = ls[x + 1] if (x + 1) in ls else 0
if left + right + 1 > result[1] - result[0]:
result = (x - left, x + right)
ls[x] = left + right + 1
ls[x - left] = left + right + 1
ls[x + right] = left + right + 1
return result
On Sun, Aug 5, 2012 at 11:40 AM, payal gupta <[email protected]> wrote:
> Find the longest
> subarray which consists of numbers that can be arranged in a continuous
> sequence.
> For ex- {4,5,1,5,7,6,8,4,1}
> output-{5,7,6,8,4}.Find the longest.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/MuACHn8S8vUJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.