the time complexity for this approach will be O(n^2) instead of O(n).Suppose each time a potential left boundary element comes up ,you will traverse the whole streak again and again.And an element will be traversed at most N times instead of 2 times.
I think something is wrong in this video
suppose elements in array are 7,6,5,4,3,2,1,it will take O(n^2) with above approach.
@chhabrapiyush480
hello piyush,
s.find() takes O(1) time for unordered set so in your test case for each element we will perform 2 operations only i,e current and current +1 . so total operations will be n*2 which is O(n) only
iterations 1 -> 7,6,5,4,3,2,1
iterations 2 -> 7,6,5,4,3,2,1
iterations 3 -> 7,6,5,4,3,2,1
iterations 4 -> 7,6,5,4,3,2,1
iterations 5 ->7,6,5,4,3,2,1
iterations 6 ->7,6,5,4,3,2,1
iterations 7 ->7,6,5,4,3,2,1
iterations 8 ->7,6,5,4,3,2,1
iterations 9 ->7,6,5,4,3,2,1
iterations 10 ->7,6,5,4,3,2,1
iterations 11 ->7,6,5,4,3,2,1
iterations 12->7,6,5,4,3,2,1
iterations 13->7,6,5,4,3,2,1
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.