10038. Maximize the Number of Partitions After Operations | Weekly Leetcode 379

  Рет қаралды 978

codingMohan

codingMohan

Күн бұрын

Пікірлер: 13
@riteshmangdare
@riteshmangdare 9 ай бұрын
Your explanation is very nice
@syedsohaibuddin1375
@syedsohaibuddin1375 9 ай бұрын
Your videos are helping a lot! Thank you!
@rockingbadshah1848
@rockingbadshah1848 2 ай бұрын
To do ( bottom up dp)
@saurabhthakur4952
@saurabhthakur4952 9 ай бұрын
great brother you explain every bit so well
@mukeshkumar-hy7yc
@mukeshkumar-hy7yc 9 ай бұрын
Your way of explaining the soln is tooo goood
@addictedgamerclashofclansa1251
@addictedgamerclashofclansa1251 8 ай бұрын
Hey,, I didn't quite understand what are we doing after we change a character to something else
@hrithikkumar7974
@hrithikkumar7974 9 ай бұрын
when we try all possibility for start index of any segment and if it becomes equal to the previous segment's ending char then no of segments before the start of current segment will change because current start index will then become part of previous segment .Would that not cause any problem?
@AnatoliySokolov-pb2bo
@AnatoliySokolov-pb2bo 9 ай бұрын
would be great if you can make a video explaining why recursive solution fits constraints. No one in the solutions really explained it well.
@josephaj8310
@josephaj8310 9 ай бұрын
Bro, how did you find that it will be easy to optimise N, rather than optimising 26.N
@amitbajpai6265
@amitbajpai6265 9 ай бұрын
Why don't you use bit manipulation to find the distinct character I think it will save the space and time more.
@codingmohan
@codingmohan 9 ай бұрын
How will you do that with bit manipulation? The bitwise OR of the mask will help in finding distinct elements in a prefix but as you can't find bitwise OR of a range (L, R) given the bitwise OR of (0, L) and (0, R), I don't think we can find that without using a range query data structures like Segment Trees. Having said that using segment tree will take 0(logN) time which is slightly better then 0(26). Do you have any reference code so that I can understand bitwise solution a bit more?
@AnatoliySokolov-pb2bo
@AnatoliySokolov-pb2bo 9 ай бұрын
@@codingmohan Here's a Python DP Solution I wrote after looking at bitmask solutions. Idea is basically you store a bitmask for the letters that you have seen currently, and also use index and if you have changed a letter yet. Then for every index if your bitmask has more 1's than k you start a new mask. Thing I really don't get though about this dp solution is how its not a TLE since you can have 2^26 combos of masks if a mask is 26 bits and 10^4 or something indices but yet it runs pretty fast. I'm thinking its something about not being able to actually have every possible mask since n is only 10^4 but I'm not sure. Here's Python code, its pretty straightforward. class Solution: def maxPartitionsAfterOperations(self, s: str, k: int) -> int: masks = {} for char in s: if char not in masks: masks[char] = 1 k: res = 1 + dp(idx + 1, masks[s[idx]], can_change) else: res = dp(idx + 1, new_mask, can_change) if can_change: for i in range(26): new_mask = mask | (1 k: res = max(res,1 + dp(idx + 1, 1
@tommyshelby6277
@tommyshelby6277 9 ай бұрын
If catastrophe was a question
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 11 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,7 МЛН
Когда отец одевает ребёнка @JaySharon
00:16
История одного вокалиста
Рет қаралды 16 МЛН
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 3,8 МЛН
22 Blind 75 | Longest Common Subsequence
35:53
ak tiwari
Рет қаралды 11
3003. Maximize the Number of Partitions After Operations (Leetcode Hard)
51:14
Programming Live with Larry
Рет қаралды 483
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 189 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 341 М.
LeetCode 1994. The Number of Good Subsets
29:02
Happy Coding
Рет қаралды 2,1 М.
兔子姐姐最终逃走了吗?#小丑#兔子警官#家庭
00:58
小蚂蚁和小宇宙
Рет қаралды 11 МЛН