Master Data Structures & Algorithms for FREE at AlgoMap.io/
@hbhavsiАй бұрын
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!
@christianjt70183 ай бұрын
I liked this solution a lot more than the previous one, keep up the amazing work!
@GregHogg3 ай бұрын
Yeah this one is better. Thank you for being a paid member!!
@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
@user-jm6gp2qc8x2 ай бұрын
whoever gave the title to this problem knew what he was doing lol
@anna-plink3 ай бұрын
One of my favorite solutions for a problem so far 👍
@GregHogg3 ай бұрын
Yeah it's pretty neat
@pravinprince32214 ай бұрын
Thank you Greg for the wonderful video, it is so helpful for me and my team, thanks again
@GregHogg4 ай бұрын
Glad to hear it!
@malakggh2 ай бұрын
That was a very good explanation!
@venkateshkannan73983 ай бұрын
Best explanation👌
@Nechss13 күн бұрын
is using sort in the spirit of these problems?
@sirojiddinSoftwareEngineer2 ай бұрын
Good job
@mehdismaeili37434 ай бұрын
Excellent .
@mahmoudelazb80284 ай бұрын
What about using set instead of filtration that we do? Keep in course you'r good instructor
@TM40_AerialAce4 ай бұрын
Elements in an a triplet can repeat, it's just the triplets themselves that have to be unique
@mahmoudelazb80283 ай бұрын
@@TM40_AerialAce I have solved it with hash set it's a simple solutions more than this
@flynnblu69923 ай бұрын
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]:
@brianwkinyua2 ай бұрын
Just before that part, high is decreased: else: res.append([offset, nums[low], nums[high]]) low += 1 high -= 1 #
@thomasthedankengine54004 ай бұрын
What about the time complexity that came from sorting? Wouldn't it be like nlog(n) times n²?
@endless91423 ай бұрын
You sort only once, so its nlog(n) PLUS n^2, which simplifies to n^2
@user-jm6gp2qc8x2 ай бұрын
greg i dont think hashmap 3sum video you've done
@2EOGIY4 ай бұрын
8:51 What's the point of using a for loop if you do not intend to iterate through all elements?
@TM40_AerialAce4 ай бұрын
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
@2EOGIY4 ай бұрын
@@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.
@wilderclover33543 ай бұрын
@@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
@Redaxi2 ай бұрын
@@2EOGIY you can use either while or for loop for any use case they are literally just syntax differences.