Тёмный

3Sum | LeetCode 15 | C++, Java, Python 

Knowledge Center
Подписаться 57 тыс.
Просмотров 38 тыс.
50% 1

Опубликовано:

 

11 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 49   
@bittupandey6645
@bittupandey6645 2 года назад
I always look for your explanation it is crisp and clear !!
@KnowledgeCenter
@KnowledgeCenter 2 года назад
Thanks.
@mukultaneja7243
@mukultaneja7243 4 года назад
2 pointer approach is awesome. But sir can we do it with DP...? I spent 3 hours in it....I even took 4D DP array but but didn't get correct solution. It was easily done with the help of (coin change) recursion.
@somyasrivastava6315
@somyasrivastava6315 3 года назад
One word for this... beautiful
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks.
@jlo4033
@jlo4033 3 года назад
Thanks a lot! helps me figur out how to code it.
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Glad to hear.
@267praveen
@267praveen 3 года назад
Hi Won' t the logic you explained for 2-SUM change the indices post sorting? In order to use the left-right logic, we need to sort the array. Once sorted, the indices will get updated. So the i and j will reflect indices of sorted array not the original array. Can you please clarify?
@AbhishekKumar-eh6zy
@AbhishekKumar-eh6zy 3 года назад
air your explanation is the best
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks a lot 😊
@Mr.Starmaker
@Mr.Starmaker 4 года назад
Amazing !! Loved this Time order and code together thank you
@KnowledgeCenter
@KnowledgeCenter 4 года назад
Thank you!
@emanejaz1501
@emanejaz1501 3 года назад
Thankyou for the effort. You explained it really well.
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks.
@AshishRawat-zl6te
@AshishRawat-zl6te 3 года назад
Great explanation!!!
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks.
@rishisharma5249
@rishisharma5249 4 года назад
Awesome video sir!!! Keep posting them
@KnowledgeCenter
@KnowledgeCenter 4 года назад
Thank you
@rishisharma5249
@rishisharma5249 4 года назад
@@KnowledgeCenter Your Welcome sir!!! Hope your channel reaches to 100K soon!
@HKabir360
@HKabir360 Год назад
Clear explanation, Thanks
@KnowledgeCenter
@KnowledgeCenter Год назад
Glad you liked it
@shaantyagi2187
@shaantyagi2187 2 года назад
Thanks
@KnowledgeCenter
@KnowledgeCenter 2 года назад
No problem
@anushsharma8645
@anushsharma8645 3 года назад
just awesome
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks.
@senthilkumar5
@senthilkumar5 3 года назад
Thank you so much for a simpler solution!!!
@GauravSingh-ku5xy
@GauravSingh-ku5xy 2 года назад
very well explained.
@KnowledgeCenter
@KnowledgeCenter 2 года назад
Glad it was helpful!
@adarshmv261
@adarshmv261 4 года назад
Just one doubt: In python code - Line 17 - i had written 'if' instead of 'elif' and one tc was failing. What diff it will make? because all 3 conditions are different right i.e summ == 0, summ < 0 and summ > 0 so anyway only either of these should execute. (btw we've to use summ not sum as var name - bcoz sum is keyword in python)
@SR-we1vl
@SR-we1vl 4 года назад
Keep up the good work!
@KnowledgeCenter
@KnowledgeCenter 4 года назад
Thanks, will do!
@kushaalrana
@kushaalrana 4 года назад
Thank you well explained👍 and we'll coded too I didn't knew the use of this -> {} operator in vector but now I do. Thanks to you👌
@KnowledgeCenter
@KnowledgeCenter 4 года назад
Great 👍
@crankyinmv
@crankyinmv 4 года назад
Thanks, This is the strategy I used as well, though I couldn't do better than 43% on the time. Maybe because I did the 2sum part as a separate function and in JS. Anyhoo, here's a possible optimization (right after line 9 in the C++ code): if(nums[i] > 0) break; ehilr
@naidusunny2744
@naidusunny2744 4 года назад
while(j < k && nums[j] == nums[j+1]) j++; while(j < k && nums[k] == nums[k-1]) k--; Can someone explain me what is the use these 2 while loops?
@abdelrahmannour1249
@abdelrahmannour1249 4 года назад
It's just like mentioned in the solution. He made the two while loops to avoid duplicate solutions for the fixed first number. So , he incremented the (j) pointer if the next element in the sorted array is equal to the the current one (which will lead to the same current solution) and the same goes for the (k) pointer but with decrementing.
@anishsuman1371
@anishsuman1371 3 года назад
Gajab search for one element in sorted array takes logn time
@vinaykaranam5957
@vinaykaranam5957 3 года назад
Brilliant!
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks.
@anandmishra8060
@anandmishra8060 4 года назад
2 while condition we are checking for sum==0.... We could check these conditions for sum>0 and sum
@mukultaneja7243
@mukultaneja7243 4 года назад
If(sum == 0) means nums[j] + nums[k] = 0. So here we have to make sure that one of these or both numbers do not repeat, as we will get duplicate answer in that, but........other if conditions do not require these while conditions as it's working the same without them.
@pratyushranjansahu9495
@pratyushranjansahu9495 4 года назад
Thanks for the explanation. Always i skip the problem..Now always i have to attain... :)
@paragroy5359
@paragroy5359 3 года назад
Nice explanation sir.......
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Thanks for liking
@paragroy5359
@paragroy5359 3 года назад
@@KnowledgeCenter Please keep on making videos on leetcode problems this is really helpful sir....
@aminesfahani3563
@aminesfahani3563 3 года назад
thanks alot
@KnowledgeCenter
@KnowledgeCenter 3 года назад
Most welcome
@KomalPal
@KomalPal 4 года назад
How could i reach u, either give yours Instagram handle or linkedin profile
@KnowledgeCenter
@KnowledgeCenter 4 года назад
www.linkedin.com/in/iitdelhi/
Далее
BeastMasters Hawk just had enough #ti13
00:30
Просмотров 358 тыс.
Cursor Is Beating VS Code (...by forking it)
18:00
Просмотров 72 тыс.
Reverse Bits | LeetCode 190 | C++, Java, Python
22:02