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

  • @reyou7
    @reyou77 жыл бұрын

    Yet another great video! Thanks G4G!

  • @rahulkumar-uw4os
    @rahulkumar-uw4os4 жыл бұрын

    sir what about sum=2 in the following example given at 0:26 using hashmap technique

  • @sounavapal762
    @sounavapal7625 жыл бұрын

    What about the extra space that we use for the hash array?

  • @NEXAMONEY
    @NEXAMONEY5 жыл бұрын

    the bool map will not work if there is repetitions in the array?

  • @yazanshakhshir3049
    @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 :(

  • @akash7752
    @akash77524 жыл бұрын

    what if sum value is -ve then how to solve using hashmap?

  • @adityavarma1077

    @adityavarma1077

    3 жыл бұрын

    use unordered set

  • @pradeepshetty3778
    @pradeepshetty37782 жыл бұрын

    how you find the indices?

  • @rapperstories5463
    @rapperstories54633 жыл бұрын

    Can someone explain third method i.e using remainders of the elements less than x....i couldnt find any video related to it

  • @hermesmercuriustrismegistu4841
    @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

    @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

    @sunfline

    2 жыл бұрын

    Python is shit

  • @divyansh59
    @divyansh595 жыл бұрын

    I like the way u r teaching sir it's geat;

  • @Sahil-explorer
    @Sahil-explorer4 жыл бұрын

    Using brute force approach we can do it too using two for loops but worst time is O(n^2).

  • @ravkrgmail
    @ravkrgmail3 жыл бұрын

    How does it work if the array has billions elements?

  • @user-ke9xj2mh4f
    @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

  • @ravindrasutar7490
    @ravindrasutar74906 жыл бұрын

    i want to display those numbers in array..

  • @axel9194
    @axel91942 жыл бұрын

    In hash method the program not working

  • @DigitalOutlawed
    @DigitalOutlawed4 жыл бұрын

    thank you soooooooooo much my kind sir

  • @nshukla6
    @nshukla67 жыл бұрын

    With Hashing technique what if numbers are duplicate

  • @GeeksforGeeksVideos

    @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

    @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}.

  • @marthamontes1636
    @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???

  • @joydeepbhattacharjee5305
    @joydeepbhattacharjee53053 жыл бұрын

    The second method will never work if there is negative number in the given set of number (For C lang)

  • @mohammadmujahid8850
    @mohammadmujahid88504 жыл бұрын

    Why u r using hasmap for second method, hashset is better here.

  • @namanshah2688
    @namanshah26882 жыл бұрын

    very useful thanks !!

  • @combofriend4461
    @combofriend44612 жыл бұрын

    I don't think hashmap solution works right of there are dups

  • @rajdave9862
    @rajdave98625 жыл бұрын

    OMnS How can you think that please please omNs 🕉 please reply me How can you think like it

  • @aakashmudigonda3375
    @aakashmudigonda33754 жыл бұрын

    I didn't understand the second method

  • @wecan2729
    @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

  • @simplybish
    @simplybish5 жыл бұрын

    binMap[arr[i]] = 1 ---> This line in code will throw index out of bound if the array has negative numbers.

  • @sounavapal762

    @sounavapal762

    5 жыл бұрын

    Bishwanath Singh in this case we'll have to keep an extra check

  • @jeanettenguyen2265

    @jeanettenguyen2265

    5 жыл бұрын

    it's a dictionary/hashmap not an array

  • @joydeepbhattacharjee5305

    @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

  • @alexanderarea6157
    @alexanderarea61573 жыл бұрын

    Sliding window will work here

  • @shiveshsingh2445
    @shiveshsingh24457 жыл бұрын

    fair

  • @akshaydwivedi935
    @akshaydwivedi9355 жыл бұрын

    Basically a binary search

  • @marthamontes1636
    @marthamontes16366 жыл бұрын

    Yet i guess you made not my day :/

  • @theoneinyou2233
    @theoneinyou2233 Жыл бұрын

    Can it be simpler more like ... Map m= new HashMap(); for(i=0;i