Extra Characters in a String - Leetcode 2707 - Python

  Рет қаралды 19,325

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер
@rohitkumaram
@rohitkumaram 4 ай бұрын
I think, I need to complete the eligibility to understand, these solutions, 1st DP always pain for me , then Trie. Have marked will try again after few , hopefully that time I could understand this solution.
@poojababa67
@poojababa67 Жыл бұрын
The explanation is as neet(neat) as it could get!
@UmarKhan-rb3ts
@UmarKhan-rb3ts Жыл бұрын
The way I went about doing it is the same dp memoisation approach but instead of creating all possible substrings of the string starting the ith index, I iterated over the dictionary words and took the subtring of the given string starting ith index exactly the same length as each dictionary word. However,I don't think there is a great difference in time complexity.
@kusumjoshi4613
@kusumjoshi4613 4 ай бұрын
Can you please share that code
@shayanshahini642
@shayanshahini642 4 күн бұрын
@@kusumjoshi4613 This would be code dp = {} def dfs(ind): if ind == len(s): return 0 if ind in dp: return dp[ind] res = 1 + dfs(ind+1) for word in dictionary: if s[ind:ind + len(word)] == word: res = min(res, dfs(ind + len(word))) dp[ind] = res return res return dfs(0)
@MP-ny3ep
@MP-ny3ep Жыл бұрын
Great Explanation !
@rajrajesh1669
@rajrajesh1669 Жыл бұрын
Nice explanation
@chien-yucode992
@chien-yucode992 Жыл бұрын
YOU ARE AWESOME
@light_70
@light_70 Жыл бұрын
Thanks :)
@MartinDeveloper-j9r
@MartinDeveloper-j9r 4 ай бұрын
Hi, thanks for posting this video, this is very helpful. Quick question, why do you set dfs(j + 1) in line 33, `res = min(res, dfs(j+1)`. It seems that position, j + 1, is already calculated, so can we call the dp, `dp[j+1]` instead of doing a dfs(j + 1)? Though the if statement will catch it and call the dp. Just curious if there is reason why. Thanks :)
@pixelbyteee
@pixelbyteee 4 ай бұрын
Dp[j+1] might not be calculated yet, so we cannot guarantee a solution there... But calling recursively solves that issue
@abdulrhmankhattab9041
@abdulrhmankhattab9041 Жыл бұрын
ty
@soumyajitchatterjee5822
@soumyajitchatterjee5822 Жыл бұрын
Damn. This was a really great solution.
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk 4 ай бұрын
Please can someone correct my understanding Runtime with just recursive 2 ^(n^2) With memoization o n^2 ?
@rocmewtwo
@rocmewtwo 4 ай бұрын
slicing substring s[i:j+] also takes O(n), so with memorization is O(n^3). dfs -> n, j inner loop -> n, slicing -> n if using trie, we can reduce the time slice and compare prefixes.
@Box-iq1zj
@Box-iq1zj Ай бұрын
You don't have this leetcode problem in NeetCode All list
@ZiruiLiu
@ZiruiLiu Жыл бұрын
I really doubt if these companies will continue to select candidates based on their leetcode coding performance in the future.
@adamsmith9590
@adamsmith9590 Жыл бұрын
Why
@thepriestofvaranasi
@thepriestofvaranasi 4 ай бұрын
Why
@Rancha51
@Rancha51 Жыл бұрын
Can you please do Odd Even Jump ? been waiting for that a long time now
@Nisha.......
@Nisha....... Жыл бұрын
problem number?
@Rancha51
@Rancha51 Жыл бұрын
@@Nisha....... Leetcode 975
@Nisha.......
@Nisha....... Жыл бұрын
@@Rancha51 Just tried it using DP, here's the solution: class Solution: def oddEvenJumps(self, arr: List[int]) -> int: n=len(arr) x=[[False,False] for i in range(n)] # odd, even # set both even jump and odd jump of last element to true x[-1][0]=True x[-1][1]=True for i in range(n-2,-1,-1): cur1=[inf,inf] cur2=[-inf,inf] for j in range(i+1,n): if arr[j]>=arr[i] and arr[j]
@Rancha51
@Rancha51 Жыл бұрын
@@Nisha....... Thanks for the effort, appreciate it. But I am looking for explanation not the code.
@swastikgorai2332
@swastikgorai2332 Жыл бұрын
can we do it like word break??
@ahmedashraf3199
@ahmedashraf3199 Жыл бұрын
could u consider a c++ solution next time ? ty alot.
@高进-k1h
@高进-k1h 3 ай бұрын
what is definition of your dp,or what is subproblem definition?
K-th Smallest in Lexicographical Order - Leetcode 440 - Python
19:06
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 210 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 349 М.
Split Linked List in Parts - Leetcode 725 - Python
11:01
NeetCodeIO
Рет қаралды 13 М.
N-Queens - Backtracking - Leetcode 51 - Python
17:51
NeetCode
Рет қаралды 192 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 347 М.
This Algorithm is 1,606,240% FASTER
13:31
ThePrimeagen
Рет қаралды 864 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 361 М.
Extra Characters in a String | Leetcode 2707
16:43
Techdose
Рет қаралды 2,2 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 249 М.