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

  Рет қаралды 1,005

codingMohan

codingMohan

Күн бұрын

Пікірлер: 13
@riteshmangdare
@riteshmangdare 10 ай бұрын
Your explanation is very nice
@syedsohaibuddin1375
@syedsohaibuddin1375 10 ай бұрын
Your videos are helping a lot! Thank you!
@saurabhthakur4952
@saurabhthakur4952 10 ай бұрын
great brother you explain every bit so well
@mukeshkumar-hy7yc
@mukeshkumar-hy7yc 10 ай бұрын
Your way of explaining the soln is tooo goood
@AnatoliySokolov-pb2bo
@AnatoliySokolov-pb2bo 10 ай бұрын
would be great if you can make a video explaining why recursive solution fits constraints. No one in the solutions really explained it well.
@rockingbadshah1848
@rockingbadshah1848 3 ай бұрын
To do ( bottom up dp)
@hrithikkumar7974
@hrithikkumar7974 10 ай бұрын
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?
@addictedgamerclashofclansa1251
@addictedgamerclashofclansa1251 9 ай бұрын
Hey,, I didn't quite understand what are we doing after we change a character to something else
@josephaj8310
@josephaj8310 10 ай бұрын
Bro, how did you find that it will be easy to optimise N, rather than optimising 26.N
@tommyshelby6277
@tommyshelby6277 10 ай бұрын
If catastrophe was a question
@amitbajpai6265
@amitbajpai6265 10 ай бұрын
Why don't you use bit manipulation to find the distinct character I think it will save the space and time more.
@codingmohan
@codingmohan 10 ай бұрын
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 10 ай бұрын
@@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
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН
Thank you Santa
00:13
Nadir Show
Рет қаралды 24 МЛН
Увеличили моцареллу для @Lorenzo.bagnati
00:48
Кушать Хочу
Рет қаралды 8 МЛН
3251. Find the Count of Monotonic Pairs II | Weekly Leetcode 410
33:04
3225. Maximum Score From Grid Operations | Leetcode Biweekly 135
1:04:57
The Midpoint Circle Algorithm Explained Step by Step
13:33
NoBS Code
Рет қаралды 134 М.
3219. Minimum Cost for Cutting Cake II | Weekly Leetcode 406
1:03:26
3245. Alternating Groups III | Weekly Leetcode 409
59:38
codingMohan
Рет қаралды 1,4 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН