Find a pair with the given difference | GeeksforGeeks

preview_player
Показать описание

This video is contributed by Parikshit Kumar Pruthi

Please Like, Comment and Share the Video among your friends.

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

why not 2pointer approach working when j=n-1 initially

kumarharsh-yearb.tech.met
Автор

for second stem ur algorithm works more than o(n) if the pair is at last of the array.reply me if i wrong

jagadeeshkarada
Автор

Will this solution work if n is negative ?
A= {10, 40}
B= -30

vikrantbhati
Автор

why is the binary search approach showing tle.

ankitkumarmahato
Автор

There's a neetcode video on this that explains this even better. Can't remember what it's called though. Anyone who comments the correct answer will get a free updoot from me.

pauljones
Автор

Thanks for the video.
Well I think I have a O(n) approach here, please correct me if I'm wrong.
First we'll create a HashMap..let's name it store.
Now we'll start traversing the entire array....
For(int I=0;I<n;I++){
if(store.containsKey(a[i] - + diff))
print yes
break;
}
else
store.put(a[ i ], a[ i ]);
}
What say?
Code is in Java

psiddharth
Автор

It doesn't work for this input.
arr = {3, 6, 7, 8, 9}; n=14

DeepakKumar-vszk