Maximum Score After Splitting a String | Leetcode 1422

  Рет қаралды 3,478

Techdose

Techdose

Күн бұрын

Пікірлер
@chakri6262
@chakri6262 2 күн бұрын
I used substring function to get two substrings and got the subscore for each combination and calculated the maxScore of all the subscores. The explained algorithm is super intuitive .Thank you
@techdose4u
@techdose4u 2 күн бұрын
we should avoid creating substrings as it costs a lot on runtime
@chakri6262
@chakri6262 2 күн бұрын
Yes I got it and searched for an optimal solution. Thank you sir .
@kheersagarpatel3195
@kheersagarpatel3195 2 күн бұрын
Sir As you know some of the youtubers ask us to explain the brute force then better then optimal solution to interviewer ,so we should write seperate code for all of these? Or just we can explain orally the brute force and better approach and then go for the optimal approach for coding with explanation just like you do in your videos. Because in some topics like recursion backtracking graphs dp etc.. brute force and better approach are cumbersome to code than optimal approach.
@techdose4u
@techdose4u 2 күн бұрын
No. the burteforce and suboptimal solutions will soon be genrally skiped in a few minutes :)
@NitishKumar-vi7sq
@NitishKumar-vi7sq 2 күн бұрын
I maintained prefix sum array from left and right for 0 and 1
@techdose4u
@techdose4u 2 күн бұрын
nice
@Chetanmarathe-j6f
@Chetanmarathe-j6f 2 күн бұрын
🎉no need to take array just make 1 loop for finding out total number of one's Then just make one initialisation for sum of zeros in left and in loop increment it and just make checks if it's 1 then reduce the sum of 1 by 1 and simply take max of sum of sum of 0 and sum of 1
@NitishKumar-vi7sq
@NitishKumar-vi7sq 2 күн бұрын
@@Chetanmarathe-j6f yeah I realised later on
@UdhyaKumar-z4d
@UdhyaKumar-z4d 2 күн бұрын
Super...I tried to use two arrays one count and zero count and traverse both
@techdose4u
@techdose4u 2 күн бұрын
nice
@mgworld3342
@mgworld3342 2 күн бұрын
Best explanation
@techdose4u
@techdose4u 2 күн бұрын
🙏🏼
@ygcodecorner
@ygcodecorner 2 күн бұрын
I was just solving this question 😮😮
@techdose4u
@techdose4u 2 күн бұрын
nice
@nitheeshp.s2532
@nitheeshp.s2532 2 күн бұрын
why should we have s.size() for counting one's and s.size()-1 to check 0's
@techdose4u
@techdose4u 2 күн бұрын
because split should have 1 element on right side :) therefore need to stop at 2nd last index. I think you can take your examples and do some dry runs on my code. If you still have confusion pls post here.
@nitheeshp.s2532
@nitheeshp.s2532 2 күн бұрын
@ got it thanks
@vaibhav454
@vaibhav454 2 күн бұрын
// Approach 2 ->> 2 Iterations... // TC= O(2*N) class Solution{ public: int maxScore(string str) { int n= str.length(); vector rightOne(n,0); rightOne[n-1]= (str[n-1]- '0'); for(int i=n-2;i>=0; i--) { rightOne[i]= rightOne[i+1] + (str[i]- '0'); } int maxi= 0, cnt= 0; if(str[0]== '0') cnt= 1; for(int i=1; i Using seperate vec for cnt of zeroes on left side and ones on right side // TC= O(3*N) /* class Solution { public: int maxScore(string str) { int n= str.length(); vector leftZeroes(n,0); if(str[0]== '0') { leftZeroes[0]= 1; } for(int i=1;i=0; i--) { rightOnes[i]= rightOnes[i+1] + (str[i]-'0'); } int maxi= 0; for(int i=1; i
Count Vowel Strings in Ranges | Leetcode 2559
10:50
Techdose
Рет қаралды 3,8 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 228 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 753 М.
Stop Recommending Clean Code
27:05
ThePrimeTime
Рет қаралды 559 М.
Minimum Cost For Tickets | Leetcode 983
20:31
Techdose
Рет қаралды 2,5 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 845 М.
How to Solve ANY LeetCode Problem (Step-by-Step)
12:37
Codebagel
Рет қаралды 332 М.
Number of Ways to Split Array | Leetcode 2270
8:53
Techdose
Рет қаралды 1,9 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 186 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 247 М.