How can this Longest consecutive approach 3 is solve in O(n) time

the while loop inside the for loop can extend the comlexity

Hello @jatinkumarjk2001
the approach we are following is -
a) if current-1 element is not there in set then start iterating from current (temp variable -> x) till s.find(x) !=s.end() and increment x by one.update max accordingly
b) if current -1 is not equal to s.end() then it means current element is already considered in previous counting so we ignore it (I.e continue to next number)

so we can say every element is considered only twice i.e 2*n in worst
that’s why time complexity is O(n)