4Sum II | 4sum 2 | Four Sum II | Four Sum 2 | leetcode 454 | array

preview_player
Показать описание


Popular Playlists:



#4Sum #Array #Tuples #December #Leetcode #Medium #Algorithm #DataStructure #Java #Preparation #NG #nickode #CookCodeTravel #CCT
Рекомендации по теме
Комментарии
Автор

I looked at the solution on leetcode, made no sense. I started contemplating lifestyle choices and then I found this video. Easy to understand. Thank you! :)

VigneshRangaraj
Автор

Damn bro! the explanation was so neat!! keep it up

vivekdatta-jp
Автор

To be honest, I thought there was going to be a faster way than my O(n^2) solution, but it's good to see that you also have a similar solution.

xinliu
Автор

c++ code for same logic
class Solution {
public:
int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
map<int, int> m;

for(int c: nums3){
for(int d: nums4){
m[c+d]++;
}
}
int count =0;
for(int a:nums1){
for(int b:nums2){
if(m[-(a+b)]>0)
{
count+= m[-(a+b)];
}
}
}
return count;
}
};

prathamanand
Автор

Gr8 simple short brilliant explanation

ghazanferwahab
Автор

Why is it "count += ..." and not something like "count *= ...". These are frequencies, right? Hence, we have perhaps c+d=3 occurring 10 times, and a+b=-3 occurring 2 times, the overall number of combinations is 20, not 12. Isn't it?

conceptacid
Автор

Great Vid! You explained this very well

tommy_corey
Автор

Nice solution . can we do better than o(n^2) ?

praveenj
Автор

with the help of backtracking we can also solve this problem.

sagargupta
visit shbcf.ru