Largest consecutive subsequence

sir mentioned that approch given in this video is of O(n) but my calculation are showing me the O(n^2) compleity

@Harsh_aggarwal hey use this algorithm:

  1. Create an empty hash.
  2. Insert all array elements to hash.
  3. Do following for every element arr[i]
  4. Check if this element is the starting point of a subsequence. To check this, simply look for arr[i] – 1 in the hash, if not found, then this is the first element a subsequence.
  5. If this element is the first element, then count the number of elements in the consecutive starting with this element. Iterate from arr[i] + 1 till the last element that can be found.
  6. If the count is more than the previous longest subsequence found, then update this.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.