Longest consecutive subsequence time complexity

Question:Given an array of positive integers. Find the length of the longest sub-sequence such that elements in the subsequence are consecutive integers, the consecutive numbers can be in any order.

Attempt link:https://ide.geeksforgeeks.org/DXwAWbd0SV

I have added a comment on a for loop saying TIME COMPXITY OF THIS LOOP???.

Please explain how is the time complexity of this loop O(n)?

hi @amartyaprabhakar
it’s a bit difficult to explain the same through chat here…


refer this lecture for better understanding…

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.