it is O(nlogn) and not O(n)
Time compexity of the solution
Hey @meadri17
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)
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.