Count pairs with given sum | Array | Love Babbar DSA Sheet | Amazon🔥
Vložit
- čas přidán 17. 10. 2021
- #arrays #coding #programming #competitiveprogramming #coding #dsa
Hey, Guys in this video I have explained how we can solve the problem 'Count pairs with given sum'.
Join our Telegram Channel for more Information
🔰 Telegram Channel Link = t.me/CodeLibrary1
🔰 Telegram Discussion Group Link = t.me/CodeLibraryDiscussion
Subscribe Our 2nd Channel = / @codeupwithtwins6728
🔰 Array Playlist = • Love Babbar DSA 450 Qu...
🔰 String Playlist = • Love Babbar DSA 450 Qu...
🔰 Searching and Sorting Playlist = • Love Babbar DSA 450 Qu...
🔰 Binary Tree Playlist = • Love Babbar DSA 450 Qu...
🔰 Linked List Playlist = • Love Babbar DSA 450 Qu...
🔰 Graph Playlist = • Love Babbar DSA 450 Qu...
🔰 Dynamic Programming Playlist = • Love Babbar DSA 450 Qu...
🔰 Informative Videos = • Informative Videos
🔰 Love Babbar DSA Sheet: drive.google.com/file/d/1FMdN...
Follow us on Instagram:
🔰 Shailesh Yogendra: / shaileshyogendra
🔰 Yogesh Yogendra: / i_am_yogesh_here
Follow us on LinkedIn:
🔰 Yogesh Yogendra: / yogesh-yogendra-26bbb518a
🔰 Shailesh Yogendra: / shailesh-yogendra-8b13...
Hope you like it. Comment if you have any doubt
LIKE | SHARE | SUBSCRIBE
beautiful explanation....gfg explanation ise bhi bht acha aur easier ..great one bhai!
Great explanation ,till now I was just wondering that why we are doing sum -arr[i] but now it is all clear thanks alot!
Really thankyou bhaiya for such a easy explanation although i have not study map but your easy explanation made it easier for me to understand
intuitive approach and good explanation ! thanks
simple, best and less taking time explanation video
Great one,
For python use counter() which is a subclass of dict.
nice explaination
Well explained mate!
Bhai boht badiya 👏🔥
Nice explanation
great explaination brother!
Nice explaination
Forever grateful for you bhai, because of you I got my first job
Congrats Neha!
nice explanation
Good explanation
bhaiya aap pentab kaun saa use krte ho...can you please mention the link in reply
good work brother aapki wajah se data structure seekh paya mai
Greatly
Hello sir I am preparing for amazon interview. Can i use python language to code during interview.
Interestingly, if it was to print all the pairs then using map also time complexity is O(n^2). because for every element in the given array we need to run a loop upto key_count stored in map. the worst case is [ 2,2,2,2] ans target is 4.
Searching in an unordered map is O(1)
bhaiya agr iski jagah 2 pointer approach use krenge to kya tc jyada ho jayegi array ko sort krne ke chakkar mein
very clearly explained thanks bhai
Your DSA solution video is very helpful 🥰
you can talk in english throughout the video which will help who doesnt understand hindi.
Amazing explanation 👏 👌 👍
I tried by implementing this with input 1,1,1,-1,-1,-1 is giving 6 output, but actual output is 9.
Bhai constraints me saare elements positive de rakhe hai..
This approach wont work for negatives i guess.
sort then try this it will work
Bhaiya please isko jaldi poora krke dp ko kariye please
bhai ji ye mila na question ka ans gfg be text pdh ke to kuch samaj hi ni aa raha tha...Thanks
Brute force algorithm not work sir
awesome explanation
Bro love babbar DSA sheet ke baaki problems ke soultions ki video kab aayegi?
map mein check karne se pehle ki element hai ya nahi, array ko toh map ke andar dala hi nahi...bhaiya samajh nahi aya
find number of pairs of 5 which can made with natural numbers
Ye kya hai chutiye
Thanks for this solution 🙏🏻🙏🏻🙏🏻🙏🏻
yup
plz plz upload for jAVA also
// { Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
public class GFG {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine().trim());
while (tc-- > 0) {
String[] inputLine;
inputLine = br.readLine().trim().split(" ");
int n = Integer.parseInt(inputLine[0]);
int k = Integer.parseInt(inputLine[1]);
int[] arr = new int[n];
inputLine = br.readLine().trim().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(inputLine[i]);
}
int ans = new Solution().getPairsCount(arr, n, k);
System.out.println(ans);
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution {
int getPairsCount(int[] arr, int n, int k) {
// code here
int count =0;
HashMap mapValue = new HashMap();
for(int i=0; i
man this was easy prblm😑😑
what is unordered map ? at 3:11 ? is it on java also?
Bro try dictionary in java
Bro it’s just like dictionaries initially all are false ie zeros so frequencies are adding 2nd above return statement and they are counting inside if when they encounter use dict I use python same doubt came sorted with dict
tru hashmap in java
Please Explain concepts in English
Only two pointers works when same type of intution ques on codeforces
6:00 why didn't you add 7 in map??
because it was greater than k
please write the code in java also
// { Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
public class GFG {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine().trim());
while (tc-- > 0) {
String[] inputLine;
inputLine = br.readLine().trim().split(" ");
int n = Integer.parseInt(inputLine[0]);
int k = Integer.parseInt(inputLine[1]);
int[] arr = new int[n];
inputLine = br.readLine().trim().split(" ");
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(inputLine[i]);
}
int ans = new Solution().getPairsCount(arr, n, k);
System.out.println(ans);
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution {
int getPairsCount(int[] arr, int n, int k) {
// code here
int count =0;
HashMap mapValue = new HashMap();
for(int i=0; i
Can somebody help me with this c# code? I am not able to get the expected result. Urgent please
public static int FindMaxNumForMaxSum(int[] nums, int k)
{
int result = 0;
int N = nums.Length;
var map = new Dictionary();
//[1, 5, 3, 3, 3],.. k = 6
for (var i = 0; i < N; i++)
{
var complement = k = nums[i];
if (map.ContainsKey(complement))
{
//we'll increase the map value at this key and assign to result
result = map[complement] += 1;
}
else
{
map.Add(k - nums[i], nums[i]);
}
} //end of for loop
return result;
}
bhai 5 months ho gaye aapne urgent kaha tha
@@rishavgupta4312 ab to 6 month ho gaye
@@hasnainraza3015 ab tho 11 months hogaye😥
@@ganeshpaih24 1 year☹
samjh nhi ayya bhai
btw iam begginer
Bhaiya ,I have just completed array in dsa.I could do this problem using loops but I don't know what is map . should I learn maps now or I should move ahead?
Yaa STL Sikh lo ekbar
luv ki stl series dekhlo
#include
#include
using namespace std;
int main()
{
vector a={1,2,3,4};
int size_a= a.size();
vector answer;
for(int i=0; i
bcoz answer is empty
r u kidding
Hope you got your answer why you are not getting the output
@@prayagrajwade8699 we have to use push_back or we have to specify the size of vector a(4)
@@mereRevyoos no need to specify size for the vector...you just have to push the elements in vector
Why do you write the title in English even though you are speaking in Hindi? God, there are several videos like these I think I should learn Hindi
Bhai saans tho le kam se kam..... Aise kya rurt k aaya tha kya??? 😂
bekar explanation kuch smhj ni aaya