Given an array A[] and a number x, check for pair in A[] with sum as x | GeeksforGeeks

  Рет қаралды 73,825

GeeksforGeeks

GeeksforGeeks

8 жыл бұрын

Explanation for the article: www.geeksforgeeks.org/write-a-...
This video is contributed by Harshit Jain.

Пікірлер: 40
@yazanshakhshir3049
@yazanshakhshir3049 6 жыл бұрын
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 :(
@reyou7
@reyou7 7 жыл бұрын
Yet another great video! Thanks G4G!
@sounavapal762
@sounavapal762 5 жыл бұрын
What about the extra space that we use for the hash array?
@rahulkumar-uw4os
@rahulkumar-uw4os 4 жыл бұрын
sir what about sum=2 in the following example given at 0:26 using hashmap technique
@akash7752
@akash7752 4 жыл бұрын
what if sum value is -ve then how to solve using hashmap?
@adityavarma1077
@adityavarma1077 4 жыл бұрын
use unordered set
@NEXAWAY
@NEXAWAY 5 жыл бұрын
the bool map will not work if there is repetitions in the array?
@hermesmercuriustrismegistu4841
@hermesmercuriustrismegistu4841 4 жыл бұрын
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
@rapperstories5463
@rapperstories5463 3 жыл бұрын
Can someone explain third method i.e using remainders of the elements less than x....i couldnt find any video related to it
@pradeepshetty3778
@pradeepshetty3778 2 жыл бұрын
how you find the indices?
@Sahil-explorer
@Sahil-explorer 4 жыл бұрын
Using brute force approach we can do it too using two for loops but worst time is O(n^2).
@ravkrgmail
@ravkrgmail 3 жыл бұрын
How does it work if the array has billions elements?
@user-ke9xj2mh4f
@user-ke9xj2mh4f 2 жыл бұрын
Wow!! Math and hashmap are two wonderful creation of the coding universe ❤️❤️❤️❤️❤️ thanks a lot! This is amazing 🤩🤩🤩🤩🤩🤩🤩🤩🤩🤩 I get the algorithm now
@divyansh59
@divyansh59 5 жыл бұрын
I like the way u r teaching sir it's geat;
@ravindrasutar7490
@ravindrasutar7490 6 жыл бұрын
i want to display those numbers in array..
@joydeepbhattacharjee5305
@joydeepbhattacharjee5305 3 жыл бұрын
The second method will never work if there is negative number in the given set of number (For C lang)
@DigitalOutlawed
@DigitalOutlawed 4 жыл бұрын
thank you soooooooooo much my kind sir
@nshukla6
@nshukla6 7 жыл бұрын
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}.
@axel9194
@axel9194 3 жыл бұрын
In hash method the program not working
@mohammadmujahid8850
@mohammadmujahid8850 4 жыл бұрын
Why u r using hasmap for second method, hashset is better here.
@namanshah2688
@namanshah2688 2 жыл бұрын
very useful thanks !!
@combofriend4461
@combofriend4461 2 жыл бұрын
I don't think hashmap solution works right of there are dups
@marthamontes1636
@marthamontes1636 6 жыл бұрын
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???
@aakashmudigonda3375
@aakashmudigonda3375 4 жыл бұрын
I didn't understand the second method
@alexanderarea6157
@alexanderarea6157 3 жыл бұрын
Sliding window will work here
@wecan2729
@wecan2729 3 жыл бұрын
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
@rajdave9862
@rajdave9862 5 жыл бұрын
OMnS How can you think that please please omNs 🕉 please reply me How can you think like it
@simplybish
@simplybish 6 жыл бұрын
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
@akshaydwivedi935
@akshaydwivedi935 5 жыл бұрын
Basically a binary search
@shiveshsingh2445
@shiveshsingh2445 7 жыл бұрын
fair
@marthamontes1636
@marthamontes1636 6 жыл бұрын
Yet i guess you made not my day :/
@theoneinyou2233
@theoneinyou2233 Жыл бұрын
Can it be simpler more like ... Map m= new HashMap(); for(i=0;i
Array - 16: Check if there exists a pair which matches given Sum
13:22
Coding Simplified
Рет қаралды 16 М.
Pythagorean Triplet in an array | GeeksforGeeks
11:04
GeeksforGeeks
Рет қаралды 33 М.
Как бесплатно замутить iphone 15 pro max
00:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 8 МЛН
Они так быстро убрались!
01:00
Аришнев
Рет қаралды 2,3 МЛН
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 104 МЛН
How I started coding from 0 and cracked Amazon, Google & Microsoft
9:43
Ashish Pratap Singh
Рет қаралды 482 М.
Floor and Ceiling in a sorted array | GeeksforGeeks
10:37
GeeksforGeeks
Рет қаралды 21 М.
Pairs with given sum in an array (code/Algorithm)
7:11
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 60 М.
Find Pairs in Array with Given Sum | Programming Tutorials
5:41
Programming Tutorials
Рет қаралды 65 М.
Count minimum steps to get the given desired array | GeeksforGeeks
8:43