Given an array A[] and a number x, check for pair in A[] with sum as x | GeeksforGeeks
Explanation for the article: www.geeksforgeeks.org/write-a-... This video is contributed by Harshit Jain.
Жүктеу.....
Пікірлер: 40
@reyou77 жыл бұрын
Yet another great video! Thanks G4G!
@rahulkumar-uw4os4 жыл бұрын
sir what about sum=2 in the following example given at 0:26 using hashmap technique
@sounavapal7625 жыл бұрын
What about the extra space that we use for the hash array?
@NEXAMONEY5 жыл бұрын
the bool map will not work if there is repetitions in the array?
@yazanshakhshir30496 жыл бұрын
if i just knew this channel before going to my last interview i would have got the job :( the interviewer asked me this question and i wasn't able to solve it using the hashmap method i am very upset to find out how much easy the solution is :(
@akash77524 жыл бұрын
what if sum value is -ve then how to solve using hashmap?
@adityavarma1077
3 жыл бұрын
use unordered set
@pradeepshetty37782 жыл бұрын
how you find the indices?
@rapperstories54633 жыл бұрын
Can someone explain third method i.e using remainders of the elements less than x....i couldnt find any video related to it
@hermesmercuriustrismegistu48414 жыл бұрын
In Python you do not need to know the range of the hash map ie Python dictionary since they have dynamic sizes. I found Python to be a very useful language for coding interviews. Anyway thx a lot for the video!
@Bhatonia_Jaat
3 жыл бұрын
u may be right but c++is way faster than python and also u can make dynamic arrays/hashmaps in cpp
@sunfline
2 жыл бұрын
Python is shit
@divyansh595 жыл бұрын
I like the way u r teaching sir it's geat;
@Sahil-explorer4 жыл бұрын
Using brute force approach we can do it too using two for loops but worst time is O(n^2).
@ravkrgmail3 жыл бұрын
How does it work if the array has billions elements?
@user-ke9xj2mh4f2 жыл бұрын
Wow!! Math and hashmap are two wonderful creation of the coding universe ❤️❤️❤️❤️❤️ thanks a lot! This is amazing 🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩 I get the algorithm now
@ravindrasutar74906 жыл бұрын
i want to display those numbers in array..
@axel91942 жыл бұрын
In hash method the program not working
@DigitalOutlawed4 жыл бұрын
thank you soooooooooo much my kind sir
@nshukla67 жыл бұрын
With Hashing technique what if numbers are duplicate
@GeeksforGeeksVideos
7 жыл бұрын
Hi Nitin, If the numbers are duplicate, then the algorithm will set the binary hash map twice. So, we will still get the same results.
@ishumba
3 жыл бұрын
@@GeeksforGeeksVideos Given an array [1, 5, 3, 3, 3] and sum 6, this algorithm gives a result of 3 instead of 4 being {1,5}, {3,3}, {3,3}, {3,3}.
@marthamontes16366 жыл бұрын
Damn i need to know wtf the sum is im in third im thinking about it so hard what about you give the awnser to the ppl???
@joydeepbhattacharjee53053 жыл бұрын
The second method will never work if there is negative number in the given set of number (For C lang)
@mohammadmujahid88504 жыл бұрын
Why u r using hasmap for second method, hashset is better here.
@namanshah26882 жыл бұрын
very useful thanks !!
@combofriend44612 жыл бұрын
I don't think hashmap solution works right of there are dups
@rajdave98625 жыл бұрын
OMnS How can you think that please please omNs 🕉 please reply me How can you think like it
@aakashmudigonda33754 жыл бұрын
I didn't understand the second method
@wecan27293 жыл бұрын
class Solution{ public: // Function to check if array has 2 elements // whose sum is equal to the given value bool hasArrayTwoCandidates(int arr[], int n, int x) { mapmp; for(int i=0;i
@simplybish5 жыл бұрын
binMap[arr[i]] = 1 ---> This line in code will throw index out of bound if the array has negative numbers.
@sounavapal762
5 жыл бұрын
Bishwanath Singh in this case we'll have to keep an extra check
@jeanettenguyen2265
5 жыл бұрын
it's a dictionary/hashmap not an array
@joydeepbhattacharjee5305
3 жыл бұрын
@@jeanettenguyen2265 well C lang dont have dictionary or hashmap so this approach can be done with C Bishwanath Singh is most probably talking about C lang
@alexanderarea61573 жыл бұрын
Sliding window will work here
@shiveshsingh24457 жыл бұрын
fair
@akshaydwivedi9355 жыл бұрын
Basically a binary search
@marthamontes16366 жыл бұрын
Yet i guess you made not my day :/
@theoneinyou2233 Жыл бұрын
Can it be simpler more like ... Map m= new HashMap(); for(i=0;i
Пікірлер: 40
Yet another great video! Thanks G4G!
sir what about sum=2 in the following example given at 0:26 using hashmap technique
What about the extra space that we use for the hash array?
the bool map will not work if there is repetitions in the array?
if i just knew this channel before going to my last interview i would have got the job :( the interviewer asked me this question and i wasn't able to solve it using the hashmap method i am very upset to find out how much easy the solution is :(
what if sum value is -ve then how to solve using hashmap?
@adityavarma1077
3 жыл бұрын
use unordered set
how you find the indices?
Can someone explain third method i.e using remainders of the elements less than x....i couldnt find any video related to it
In Python you do not need to know the range of the hash map ie Python dictionary since they have dynamic sizes. I found Python to be a very useful language for coding interviews. Anyway thx a lot for the video!
@Bhatonia_Jaat
3 жыл бұрын
u may be right but c++is way faster than python and also u can make dynamic arrays/hashmaps in cpp
@sunfline
2 жыл бұрын
Python is shit
I like the way u r teaching sir it's geat;
Using brute force approach we can do it too using two for loops but worst time is O(n^2).
How does it work if the array has billions elements?
Wow!! Math and hashmap are two wonderful creation of the coding universe ❤️❤️❤️❤️❤️ thanks a lot! This is amazing 🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩 I get the algorithm now
i want to display those numbers in array..
In hash method the program not working
thank you soooooooooo much my kind sir
With Hashing technique what if numbers are duplicate
@GeeksforGeeksVideos
7 жыл бұрын
Hi Nitin, If the numbers are duplicate, then the algorithm will set the binary hash map twice. So, we will still get the same results.
@ishumba
3 жыл бұрын
@@GeeksforGeeksVideos Given an array [1, 5, 3, 3, 3] and sum 6, this algorithm gives a result of 3 instead of 4 being {1,5}, {3,3}, {3,3}, {3,3}.
Damn i need to know wtf the sum is im in third im thinking about it so hard what about you give the awnser to the ppl???
The second method will never work if there is negative number in the given set of number (For C lang)
Why u r using hasmap for second method, hashset is better here.
very useful thanks !!
I don't think hashmap solution works right of there are dups
OMnS How can you think that please please omNs 🕉 please reply me How can you think like it
I didn't understand the second method
class Solution{ public: // Function to check if array has 2 elements // whose sum is equal to the given value bool hasArrayTwoCandidates(int arr[], int n, int x) { mapmp; for(int i=0;i
binMap[arr[i]] = 1 ---> This line in code will throw index out of bound if the array has negative numbers.
@sounavapal762
5 жыл бұрын
Bishwanath Singh in this case we'll have to keep an extra check
@jeanettenguyen2265
5 жыл бұрын
it's a dictionary/hashmap not an array
@joydeepbhattacharjee5305
3 жыл бұрын
@@jeanettenguyen2265 well C lang dont have dictionary or hashmap so this approach can be done with C Bishwanath Singh is most probably talking about C lang
Sliding window will work here
fair
Basically a binary search
Yet i guess you made not my day :/
Can it be simpler more like ... Map m= new HashMap(); for(i=0;i