No video

Is Subsequence - Leetcode 392

  Рет қаралды 47,812

NeetCode

NeetCode

Күн бұрын

Пікірлер: 41
@sanchayeetasir
@sanchayeetasir 2 жыл бұрын
Why is like after watching your explanations, every problem looks easy!
@josecabrera7947
@josecabrera7947 2 жыл бұрын
Dude mark my words if I get this internship with google or amazon in Seattle for summer 2023 I will personally take you to dinner !!!!
@servantofthelord8147
@servantofthelord8147 3 ай бұрын
were you able to get it?
@illu1na
@illu1na 11 ай бұрын
Can you also cover the follow up question for this problem please?
@a4rdev
@a4rdev 2 жыл бұрын
Was struggling to understand two pointers. This is a great place to start. Thanks
@navaneethmkrishnan6374
@navaneethmkrishnan6374 2 жыл бұрын
A lot of people ask why the question is given under the DP tag. This is because to find the length of the longest common subsequence, we need DP.
@nanoname5226
@nanoname5226 3 жыл бұрын
Could you also address the follow up element of this problem? The one that talks about a stream of query strings "s" coming in.
@vasujhawar.6987
@vasujhawar.6987 11 ай бұрын
thats why I came here
@jayjw1
@jayjw1 8 ай бұрын
I'm not sure if there's more to it, but wouldn't you just check if s > t: return False automatically because s can't be a subsequence if it's larger than the entirety of t?
@gamba3685
@gamba3685 4 күн бұрын
@@jayjw1 No, the follow-up element isnt talking about any specific s, it's talking about how to be more efficient if there are multiple s being sent to our function, how can we evaluate each s in an efficient way?
@farrukhniaz3218
@farrukhniaz3218 Жыл бұрын
instead of if else in return statement, write return i == len(s)
@buzunoorrishika8690
@buzunoorrishika8690 Жыл бұрын
Thank you so much I was able to write my own Java code by using your logic
@achraftasfaout2960
@achraftasfaout2960 2 жыл бұрын
Pretty neet answer, thanks. The return statement could've been: return i == len(s)
@fanyang9777
@fanyang9777 3 жыл бұрын
awesome lesson as always!
@jaideepsingh7955
@jaideepsingh7955 2 жыл бұрын
How is this a DP problem ? Can u plz elaborate how this is breaking up into overlapping subproblems and optimal substructure ?
@navaneethmkrishnan6374
@navaneethmkrishnan6374 2 жыл бұрын
To find the length of the LCS, we need DP. This one is a simple two-pointer solution.
@anutoshghosh7893
@anutoshghosh7893 6 ай бұрын
In the two pointer approach, I did not understand one thing the ordering also has to be checked in a subsequence which is missing for the problem in the testcases, for instance here s = "acg" and t = "ahbgdc", they are considering s as a subsequence of t which should not be so, as the ordering is not maintained, although all elements are present from s in t.
@ryanbaker7419
@ryanbaker7419 Ай бұрын
did u ever figure it out? im wondering the same
@danielsun716
@danielsun716 Жыл бұрын
DP solution: It is easy to think of this if you finished 10. regular expression matching. def isSubsequence(self, s: str, t: str) -> bool: if len(s) > len(t): return False dp = [[False] * (len(t) + 1) for _ in range(len(s) + 1)] for j in range(len(t) + 1): dp[len(s)][j] = True for i in range(len(s) - 1, -1, -1): for j in range(len(t) - 1, -1, -1): match = s[i] == t[j] if match: dp[i][j] = dp[i + 1][j + 1] else: dp[i][j] = dp[i][j + 1] return dp[0][0]
@iosifpuha6114
@iosifpuha6114 Жыл бұрын
this man is a hero
@cryptohamsterx
@cryptohamsterx 5 ай бұрын
bro are you genius!!
@flatmapper
@flatmapper Жыл бұрын
Thank you NeetCode. One can just return `i == len(s)`
@arunimachakraborty1175
@arunimachakraborty1175 10 ай бұрын
Thank you so much. You saved my day
@akshatverma838
@akshatverma838 5 ай бұрын
you earned a subscriber today 👍👍.
@sa25078
@sa25078 2 жыл бұрын
Thanks a lot .This video helped me a lot !!
@krateskim4169
@krateskim4169 11 ай бұрын
Awesome explanation
@bilalmohammad4242
@bilalmohammad4242 Жыл бұрын
Thank you very much!
@lamatenzin8756
@lamatenzin8756 Жыл бұрын
but wouldn't the while loop keeping looping endlessly if i is never incremented? because your'e only incrementing i if s[i] = s[j]. what if it never equals ?
@srx2106
@srx2106 10 ай бұрын
then j will keep incrementing and eventually stop the loop
@love2code_official
@love2code_official 3 жыл бұрын
Thank you bro.A love from tamil nadu
@RocketPropelledWombat
@RocketPropelledWombat Жыл бұрын
This one killed me for some stupid reason -.-
@elias043011
@elias043011 3 ай бұрын
return i == len(s) concise
@yashsolanki069
@yashsolanki069 8 ай бұрын
I'm still Scratching my head, what if it's not in the sequence?
@sanjeevacham2400
@sanjeevacham2400 2 жыл бұрын
Excellent
@sriramprasanth3390
@sriramprasanth3390 3 жыл бұрын
Bro what if it is wrong order acb,abcdef
@Track-Tor
@Track-Tor 3 жыл бұрын
he explains it at 1:32
@DanhWasHere
@DanhWasHere 3 жыл бұрын
Then it won't be a subsequence, as he explained
@kanikasaxena8603
@kanikasaxena8603 Жыл бұрын
It is handled through increment of j
@praneeth8380
@praneeth8380 2 ай бұрын
def isSubsequence(s, t): if all(j in t for j in s): return True else: return False
@joshua_dlima
@joshua_dlima 2 жыл бұрын
thank you so much!
Coin Change - Dynamic Programming Bottom Up - Leetcode 322
19:23
Decode String - Leetcode 394 - Python
16:26
NeetCode
Рет қаралды 84 М.
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 39 МЛН
Ransom Note - Leetcode 383 - Hashmaps & Sets (Python)
8:34
Greg Hogg
Рет қаралды 5 М.
Leetcode 128 - LONGEST CONSECUTIVE SEQUENCE
9:24
NeetCode
Рет қаралды 347 М.
Jump Game - Greedy - Leetcode 55
16:28
NeetCode
Рет қаралды 234 М.
Rotate Image - Matrix - Leetcode 48
15:46
NeetCode
Рет қаралды 228 М.
Minimum Size Subarray Sum - Leetcode 209 - Python
12:30
NeetCode
Рет қаралды 87 М.
USA Nice Olympiad Exponential Equation | Solve for X
6:38
Learncommunolizer
Рет қаралды 10 М.
Rotate Array - Leetcode 189 - Python
8:59
NeetCode
Рет қаралды 144 М.