454. 4Sum II (Leetcode Problem)

preview_player
Показать описание
@CodeChef @GeeksforGeeks @Leetcodes #leetcode #geeksforgeeks #adobe #amazon #microsoft #dailychallenge #technicalinterview #problemoftheday

Solution Code: Available in comment section

Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:

0 = i, j, k, l n
nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0
Рекомендации по теме
Комментарии
Автор

Solution Code:
public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
HashMap<Integer, Integer> hm1=new HashMap<>();
HashMap<Integer, Integer> hm2=new HashMap<>();
for(int i=0;i<nums1.length;i++)
{
for(int j=0;j<nums2.length;j++)
{
int sum=nums1[i]+nums2[j];
hm1.putIfAbsent(sum, 0);
hm1.put(sum, hm1.get(sum)+1);
}
}
for(int i=0;i<nums3.length;i++)
{
for(int j=0;j<nums4.length;j++)
{
int sum=nums3[i]+nums4[j];
hm2.putIfAbsent(sum, 0);
hm2.put(sum, hm2.get(sum)+1);
}
}
int count=0;
for(Map.Entry m:hm1.entrySet())
{
int key=(int)m.getKey();
int value=(int)m.getValue();
if(hm2.containsKey(-key))
{

}

}
return count;


}

viralSongsBollywood
Автор

Great expanation! Thanks for such a great explanation and your continuity as well.

ChandraShekhar-bycd
Автор

Bhaiya plz, continue with leetcode daily challenge

sumitrakumarishaw
visit shbcf.ru