Find the biggest interval that has all its members in list in O(n) [duplicate]
This question already has an answer here: Finding contiguous ranges in arrays 8 answers Longest Consecutive Sequence in an Unsorted Array [duplicate] 8 answers I was asked this in an interview. Given a list of integers, How can we find the biggest interval that has all its members in the given list? E.g. given list 1,3,5,7,4,6,10 then answer would be [3, 7]. Because it has all the elements between 3 and 7. I tried to answer but I wasn't convincing. The approach I took was to first sort the list and then check it for the biggest interval. But I was asked to do so in O(n) . I know a solution