Increasing Triplet Subsequence - LeetCode 334 - Python [O(n) time and O(1) space]

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

Explaining how to solve Increasing Triplet Subsequence in Python

@1:23 Example walkthrough
@6:14 Code
@8:27 Code run-through + final example
Music: Bensound
Lemme know if you have any comments or questions!:)))
Рекомендации по теме
Комментарии
Автор

The dry run at the end of the tutorial made the whole thing more comprehensible to me. Thanks for such an explanation.

NayemUddinBiswas-ym
Автор

Compared to other tutorials, you explained it in a way that is easy to understand. Giving more examples and going through the whole algorithm really helps. Thanks, I love it!

neilijason
Автор

One of the finest explanations you'll find on the internet.

chittillavenkataviswanath
Автор

You're the first person to make this easy to understand! Thank you!

ZanarkandStarplayer
Автор

It took some time for me to understand why this logic works. Correct me if I am wrong:
At any step the current value at nums_i or nums_j does not matter as long as they have some value that is not +infinity.
What this means is, if we have reached the line: else return true it means there is already a value set at nums_j and that also means somewhere in the iteration we have set a value at nums_i which is less than the current nums_j [ ** irrespective of the current nums_i ** ].

amartyaganguly
Автор

Such a simple solution. Can't believe I didn't think of this.

sai-codes
Автор

Best and simplest solution with a neat explanation. Thanks Deepti

lakshmiivaturi-ot
Автор

Her solution was so easy it made realize that I overthink too much lmao

bryankhor
Автор

Thank you for saving me hours of headache!

ers
Автор

Great video. This makes sense after watching this video about 3 times. Sad, I don't think I would have come up with this solution.

thanhn
Автор

You explained this very well - much appreciated :-)

angushardy-francis
Автор

this is the only video i can coprehend for lc. 334. thx

PeakyBlinder-lzgh
Автор

i = 0

while i < len(nums):
if nums[i] < nums[i+1] and nums[i+1] < nums[i+2] or nums[i] < len(nums) - 1:
return (True)
else:
return (False)
i += 1

ICloudyFi
Автор

Thanks for this video. I don't know why I was stuck at j < i case.

makealemonade
Автор

the solution doesn't satisfy for this array - [20, 100, 10, 12, 5, 13]. If you dry run it to verify, it doesn't satisfy the condition i<j<k. At 5th iteration - num_i = 10, num_j=12 and num=5, when runs inside loop, it passes through first if condition and num_i becomes 5. At 6th iteration, num = 13 and it doesn't pass through any of the if condition hence returning true. But at this point, num_i = 5, num_j = 12, num=13 and indices are i=4, j=3, and k=5 which doesn't satisfy the condition i<j<k. Hence this solution is not correct.

manishamuskan
Автор

Thanks a lot Deepti. Explanation was great !

ankitpandey
Автор

Congrats on getting a complete submission. However, I think this LeetCode Problem is broken.

What happens if your solution was applied to this? nums = [20, 100, 10, 12, 5, 13]

What happens if num_i is updated but now it's index value is greater than num_j's? This would break the i < j < k condition, however, you don't see that in some solutions I've seen that were submitted.

nick
Автор

Hey Deepti... your videos are really amazing... can you please do a video on this problem..

Input: [”long”, “very”, ”jump”, ”verylongjump”, “longjump”, ”iconstar”, ”star”, ”icon”, ”icons”, ”tar”, ”stars, ”iconstars”]

output:
“verylongjump”: [“very”, ”long”, ”jump”]
“verylongjump”: [“very”, ”longjump”]
“iconstar”: [“icon”, ””star”]
“iconstar”:[“icons”, ”tar”]
“iconstars”:[“icon”, ”stars”]

johnming
Автор

Consider the following array to be our input: [20, 100, 10, 12, 5, 13]
i will be 5
j will be 12
and k will be 13
and it will return True. however this is not a correct subsequence because j come before i not the opposite
I can't understand why is this a correct solution (I understand we don't return the indexes so our solution is correct because it returns true because 10 can be i 12 can be j 13 can be k)

I found this solution is widely used and i would appropriate it if someone explain to me why is it correct

ahmdrn
Автор

Its works for this problem but what if similar kind of problems like return first three numbers of those pair.For example[2, 1, 3, 0, 4, 6] in this i want to return those first pair as 1, 4, 6 how can we solve these type of questions

PersonalUser-yrvb