this solution is having time complexity O(n^2) istead of O(n).
This is taking O(n^2) instead of O(n)
@chhabrapiyush480
Hello Piyush,
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)
suppose first element is 7,so max will be updated to 1,
understood ,i was thinking some thing else.