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

  Рет қаралды 13,660

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 31
@GregHogg
@GregHogg 4 ай бұрын
Master Data Structures & Algorithms for FREE at AlgoMap.io/
@hbhavsi
@hbhavsi 2 ай бұрын
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!
@user-jm6gp2qc8x
@user-jm6gp2qc8x 3 ай бұрын
whoever gave the title to this problem knew what he was doing lol
@christianjt7018
@christianjt7018 5 ай бұрын
I liked this solution a lot more than the previous one, keep up the amazing work!
@GregHogg
@GregHogg 5 ай бұрын
Yeah this one is better. Thank you for being a paid member!!
@WatchNoah
@WatchNoah 3 ай бұрын
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
@anna-plink
@anna-plink 4 ай бұрын
One of my favorite solutions for a problem so far 👍
@GregHogg
@GregHogg 4 ай бұрын
Yeah it's pretty neat
@pravinprince3221
@pravinprince3221 5 ай бұрын
Thank you Greg for the wonderful video, it is so helpful for me and my team, thanks again
@GregHogg
@GregHogg 5 ай бұрын
Glad to hear it!
@kavan3
@kavan3 15 күн бұрын
I'd recommend solving Two Sum and Two Sum II before approaching this problem
@malakggh
@malakggh 3 ай бұрын
That was a very good explanation!
@venkateshkannan7398
@venkateshkannan7398 4 ай бұрын
Best explanation👌
@Nechss
@Nechss Ай бұрын
is using sort in the spirit of these problems?
@mehdismaeili3743
@mehdismaeili3743 5 ай бұрын
Excellent .
@thomasthedankengine5400
@thomasthedankengine5400 5 ай бұрын
What about the time complexity that came from sorting? Wouldn't it be like nlog(n) times n²?
@endless9142
@endless9142 5 ай бұрын
You sort only once, so its nlog(n) PLUS n^2, which simplifies to n^2
@flynnblu6992
@flynnblu6992 4 ай бұрын
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 3 ай бұрын
Just before that part, high is decreased: else: res.append([offset, nums[low], nums[high]]) low += 1 high -= 1 #
@mahmoudelazb8028
@mahmoudelazb8028 5 ай бұрын
What about using set instead of filtration that we do? Keep in course you'r good instructor
@TM40_AerialAce
@TM40_AerialAce 5 ай бұрын
Elements in an a triplet can repeat, it's just the triplets themselves that have to be unique
@mahmoudelazb8028
@mahmoudelazb8028 5 ай бұрын
@@TM40_AerialAce I have solved it with hash set it's a simple solutions more than this
@sirojiddinSoftwareEngineer
@sirojiddinSoftwareEngineer 3 ай бұрын
Good job
@2EOGIY
@2EOGIY 5 ай бұрын
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 5 ай бұрын
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 5 ай бұрын
@@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 4 ай бұрын
​@@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 3 ай бұрын
@@2EOGIY you can use either while or for loop for any use case they are literally just syntax differences.
@user-jm6gp2qc8x
@user-jm6gp2qc8x 3 ай бұрын
greg i dont think hashmap 3sum video you've done
@skinloren69
@skinloren69 Ай бұрын
is this nums.sorting() allowed at interviews?
Valid Palindrome - Leetcode 125 - 2 Pointers (Python)
5:43
Greg Hogg
Рет қаралды 8 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 746 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
3 Sum | Brute -  Better - Optimal with Codes
38:25
take U forward
Рет қаралды 375 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 183 М.
Prefix Sum in 4 minutes | LeetCode Pattern
4:13
AlgoMasterIO
Рет қаралды 10 М.
Number of Islands - Leetcode 200 - Graphs (Python)
11:01
Greg Hogg
Рет қаралды 12 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 684 М.
I Redesigned the ENTIRE YouTube UI from Scratch
19:10
Juxtopposed
Рет қаралды 910 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 706 М.
House Robber - Leetcode 198 - Dynamic Programming (Python)
13:15