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
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.
// { 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();
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; }
// { 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();
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?
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!
simple, best and less taking time explanation video
bhaiya aap pentab kaun saa use krte ho...can you please mention the link in reply
Forever grateful for you bhai, because of you I got my first job
Congrats Neha!
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
Bhai boht badiya 👏🔥
great explaination brother!
good work brother aapki wajah se data structure seekh paya mai
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 agr iski jagah 2 pointer approach use krenge to kya tc jyada ho jayegi array ko sort krne ke chakkar mein
intuitive approach and good explanation ! thanks
Thanks for this solution 🙏🏻🙏🏻🙏🏻🙏🏻
yup
Well explained mate!
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
Brute force algorithm not work sir
Great one,
For python use counter() which is a subclass of dict.
Bhaiya please isko jaldi poora krke dp ko kariye please
very clearly explained thanks bhai
nice explaination
Hello sir I am preparing for amazon interview. Can i use python language to code during interview.
6:00 why didn't you add 7 in map??
because it was greater than k
you can talk in english throughout the video which will help who doesnt understand hindi.
map mein check karne se pehle ki element hai ya nahi, array ko toh map ke andar dala hi nahi...bhaiya samajh nahi aya
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)
bhai ji ye mila na question ka ans gfg be text pdh ke to kuch samaj hi ni aa raha tha...Thanks
Bro love babbar DSA sheet ke baaki problems ke soultions ki video kab aayegi?
find number of pairs of 5 which can made with natural numbers
Ye kya hai chutiye
Nice explanation
Your DSA solution video is very helpful 🥰
awesome explanation
Greatly
Amazing explanation 👏 👌 👍
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
Please Explain concepts in English
man this was easy prblm😑😑
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☹
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
samjh nhi ayya bhai
btw iam begginer
Only two pointers works when same type of intution ques on codeforces
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
#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
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
Bhai saans tho le kam se kam..... Aise kya rurt k aaya tha kya??? 😂
bekar explanation kuch smhj ni aaya
Nice explaination
Good explanation
nice explanation