Here in this ques ,i have doubt in video

we are sorting array , then finding out min and max …right??? so complexity should be O(max-min)+nlog(n)

No we aren’t sorting the array in the second approach, instead we are making use of hashing.
So the algorithm goes like this make one traversal and store every element in the map, or lets say some hash function. This is done in O(N)
Next step is to start an iterator from min element, which runs from min to max in the hopes of finding a subsequence.
So the total complexity is O(N)+O(Max-Min) which can be termed as O(Max-Min) if Max-Min>N

bina sort kre min or max ??? ham jabh map mei store karva rhe hoge , tabh hi min or max update krte rahege???

or ye code 4 5 6 7 8 ke liy chlana, else condition mei jayga hi nhi

why do you need to sort to get min or max? You can just keep two variables and get the min and max elements in a single traversal

Here is the pseudocode of the algorithm

for(int i=0;i<n;i++) mp[arr[i]]++;

int ans = 0, temp = 0;

while (i <= mx) {
	if (mp[i] - 1 == 0) {
		while (mp[i] != 0 && i <= mx) {
			i++;
			temp++;
		}
		ans = max(ans, temp);
	}
	i++;
}
cout << ans << endl;

}
This pseudocode runs for your sample test case and gives 5 as output.

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.