here it is told that complexity of code is O(n). But if we give an array suppose 1 2 3 4 5. then for loop will consider each one of them as the left boundary and traverse till the end to find largest subsequence. then in this case wouldnt the complexity be n^2?
Doubt in concept shown in video
@Akshita99
in the case of 1 2 3 4 5,
first i entered the number in set s.
then i traversed the array,
i = 0 , is zero present in the set? No, So i travserse in forward direction.
i = 1,2,3,4 arr[i]-1 is present in the set so, I won;t traverse in forward direction.
so that is O(n + n) = O(n)
okay got it. thank you