3Sum (Updated Solution) - Leetcode 15 - Two Pointers (Python)

  Рет қаралды 8,820

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 28
@GregHogg
@GregHogg 2 ай бұрын
Master Data Structures & Algorithms for FREE at AlgoMap.io/
@hbhavsi
@hbhavsi 24 күн бұрын
Wow, this is the clearest explanation of the solution I have come across that explains constraints with the correct example, rather than just the default example, and I am left scratching my head at the final solution, like huh, why was this needed at all? Thanks so much!
@WatchNoah
@WatchNoah Ай бұрын
instead of the two while loops in the summ == 0, you can actually also simply use a set as answer and add sorted tuples. this also has a runtime of 558ms
@christianjt7018
@christianjt7018 3 ай бұрын
I liked this solution a lot more than the previous one, keep up the amazing work!
@GregHogg
@GregHogg 3 ай бұрын
Yeah this one is better. Thank you for being a paid member!!
@anna-plink
@anna-plink 2 ай бұрын
One of my favorite solutions for a problem so far 👍
@GregHogg
@GregHogg 2 ай бұрын
Yeah it's pretty neat
@pravinprince3221
@pravinprince3221 3 ай бұрын
Thank you Greg for the wonderful video, it is so helpful for me and my team, thanks again
@GregHogg
@GregHogg 3 ай бұрын
Glad to hear it!
@malakggh
@malakggh Ай бұрын
That was a very good explanation!
@user-jm6gp2qc8x
@user-jm6gp2qc8x Ай бұрын
whoever gave the title to this problem knew what he was doing lol
@venkateshkannan7398
@venkateshkannan7398 2 ай бұрын
Best explanation👌
@mehdismaeili3743
@mehdismaeili3743 3 ай бұрын
Excellent .
@sirojiddinSoftwareEngineer
@sirojiddinSoftwareEngineer Ай бұрын
Good job
@mahmoudelazb8028
@mahmoudelazb8028 3 ай бұрын
What about using set instead of filtration that we do? Keep in course you'r good instructor
@TM40_AerialAce
@TM40_AerialAce 3 ай бұрын
Elements in an a triplet can repeat, it's just the triplets themselves that have to be unique
@mahmoudelazb8028
@mahmoudelazb8028 3 ай бұрын
@@TM40_AerialAce I have solved it with hash set it's a simple solutions more than this
@flynnblu6992
@flynnblu6992 2 ай бұрын
Love your videos! But puzzled... after finding the first answer, isn't nums[hi + 1] out of range on the following, given hi starts out as (n - 1), hence we are checking nums[n]? while hi > lo and nums[hi] == nums[hi + 1]:
@brianwkinyua
@brianwkinyua Ай бұрын
Just before that part, high is decreased: else: res.append([offset, nums[low], nums[high]]) low += 1 high -= 1 #
@thomasthedankengine5400
@thomasthedankengine5400 3 ай бұрын
What about the time complexity that came from sorting? Wouldn't it be like nlog(n) times n²?
@endless9142
@endless9142 3 ай бұрын
You sort only once, so its nlog(n) PLUS n^2, which simplifies to n^2
@user-jm6gp2qc8x
@user-jm6gp2qc8x Ай бұрын
greg i dont think hashmap 3sum video you've done
@2EOGIY
@2EOGIY 3 ай бұрын
8:51 What's the point of using a for loop if you do not intend to iterate through all elements?
@TM40_AerialAce
@TM40_AerialAce 3 ай бұрын
You do intend to iterate through almost all elements (length of array - 2, so you have space for the two pointers). the i in `for i in range(n)` acts as a boundary that squeezes the two pointers closer together every iteration. Sort of like the trash compactor scene from A New Hope
@2EOGIY
@2EOGIY 3 ай бұрын
@@TM40_AerialAce, if there is an intent for an early exit, then a for loop is a wrong choice. Just add those conditions to a while loop.
@wilderclover3354
@wilderclover3354 2 ай бұрын
​@@2EOGIYi don't think there is some rule written in python documentation that u should not used for loop in those situations. Its easier to explain by using for loop than while
@Redaxi
@Redaxi Ай бұрын
@@2EOGIY you can use either while or for loop for any use case they are literally just syntax differences.
Valid Palindrome - Leetcode 125 - 2 Pointers (Python)
5:43
Greg Hogg
Рет қаралды 7 М.
3 Sum | Brute -  Better - Optimal with Codes
38:25
take U forward
Рет қаралды 341 М.
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 88 МЛН
СОБАКА И  ТРИ ТАБАЛАПКИ Ч.2 #shorts
00:33
INNA SERG
Рет қаралды 1,7 МЛН
MAGIC TIME ​⁠@Whoispelagheya
00:28
MasomkaMagic
Рет қаралды 37 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 650 М.
Diameter of Binary Tree - Leetcode 543 - Trees (Python)
11:16
3Sum - Leetcode 15 - 2 Pointers (Python)
9:42
Greg Hogg
Рет қаралды 12 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 523 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
What REALLY is Data Science? Told by a Data Scientist
10:33
Joma Tech
Рет қаралды 3,8 МЛН
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 9 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 88 МЛН