LeetCode Day 16 - Wildcards Bracket String (I Struggle)

  Рет қаралды 29,741

Errichto Algorithms

Errichto Algorithms

Күн бұрын

Пікірлер: 221
@Learner010
@Learner010 4 жыл бұрын
It takes lots of guts to say "I struggled" it shows you are such a genuine person
@winfredj9820
@winfredj9820 4 жыл бұрын
bcoz he s true genius..
@Learner010
@Learner010 4 жыл бұрын
@@vk-vz8qo and you are dumb or what? i m just amazed to see that line and whatever i feel i write it down... as simple as it sound..
@SaidKerimov
@SaidKerimov 4 жыл бұрын
Best video so far among 30-day challenge videos. I learn more in these videos than in the videos where he says "oh I know how to solve this problem" and solves it in a second.
@LeeNau
@LeeNau 4 жыл бұрын
I prefer seeing the struggle because: 1. it helps demonstrate your thought process and iteration through the problem, 2. i feel like less of an idiot when i struggled for an hour and found no solution :)
@miteshkumar3183
@miteshkumar3183 4 жыл бұрын
'Struggled' but still solved it himself, within 30 minutes. That isn't struggling lol.
@ianpan0102
@ianpan0102 4 жыл бұрын
Kids, this is why we respect Errichto -- he's a genuine and honest person who doesn't need to prove anything to people.
@alejnaser
@alejnaser 4 жыл бұрын
Hi Errichto, a lecture on such problems would be great indeed.
@OptimisticForce
@OptimisticForce 3 жыл бұрын
We need it Yes
@navjot7397
@navjot7397 4 жыл бұрын
The first thing that came to my mind when i saw this problem was to imagine what your video solution will be
@MattYang
@MattYang 4 жыл бұрын
I liked this one pass "range" solution from the LeetCode discussion (not mine), Intuition is: 1. minOpen keeps track of the min # of left parentheses left, maxOpen keeps track of the max # of left parentheses left 2. if maxOpen dips below 0, then clearly it is invalid (using all stars won't save us). If minOpen dips below 0, we reset it to 0 by "using" a star. 3. At the end, minOpen must equal 0. We only used stars to save ourselves, if minOpen > 0 it means we didn't match all the left parantheses. int maxOpen = 0, minOpen = 0; for (char ch : s) { if (leftParantheses) { minOpen++, maxOpen++ } else if (rightParantheses){ minOpen--; maxOpen--; else if (*) { minOpen--; maxOpen++; } if (maxOpen < 0) { return false;} if (minOpen < 0) { minOpen = 0;} } return minOpen == 0;
@F0RM4T
@F0RM4T 4 жыл бұрын
I came up with an algorithm that makes either 2 or 4 arithmetic and logical operations (combined) per iteration, excluding the path that returns prematurely. In opposition to this, that makes either 5 or 6 (with the 0 insertion), excluding the path that returns prematurely.
@tuhinmukherjee8141
@tuhinmukherjee8141 4 жыл бұрын
I love how you let us go through your thought process. I'm learning a lot.
@SaidKerimov
@SaidKerimov 4 жыл бұрын
Best video so far among 30-day challenge videos. I learn more in these videos than in the videos where he says "oh I know how to solve this problem" and solves it in a second.
@adityagaykar
@adityagaykar 4 жыл бұрын
Appreciate you showing up your struggle rather than just editing that part out before posting it. It takes courage to do this.
@camper8650
@camper8650 4 жыл бұрын
i was able to get a solution but the the solution was exponential, so i waited for your video.
@mayukhchanda5805
@mayukhchanda5805 4 жыл бұрын
Even with your warning, I watched it from beginning to end. Love to see your approach towards a problem even if it doesn't turn out right. Love your videos 🤩🤩
@barongrmel3797
@barongrmel3797 4 жыл бұрын
I struggled so bad that I slept thinking about this question, and started questioning what I was doing with life. This video provide a very nice explanation, I am highly thankful to you!
@neloysinha8098
@neloysinha8098 4 жыл бұрын
14:49 u seen the meme CODE DOESN'T WORK : "WHY THOUGH ??!!" CODE WORKS :" WHY THOUGH ??!!"
@anuragporwal4664
@anuragporwal4664 4 жыл бұрын
I used two stacks of pair where pos is the index of the character in the string
@jatinlalwani8355
@jatinlalwani8355 4 жыл бұрын
Appreciate your genuinity. It's hard to find genuine channels these days. Keep it up. Wishing you all the luck for 1M subs.
@GyaneshISHU
@GyaneshISHU 4 жыл бұрын
Such an elegant solution to a seemingly complex problem
@tarekseguir201
@tarekseguir201 4 жыл бұрын
I'm watching all your series of 30 days LeetCode challenge, and I would like to think you for the effort and for being so humble I really learning a lot here.
@blancosj
@blancosj 4 жыл бұрын
Congratulations for this video. I tried linear solution first too and I ended up with dp, basically recursion and memoize. Then I finally went to solutions and review the linear solution.
@befrog57
@befrog57 4 жыл бұрын
I struggled really hard with this one. Took me atleast 1 hour to get accepted 😶 It makes me feel a little better to see you didn't solve it in 5 minutes though 😁
@ivanp4740
@ivanp4740 4 жыл бұрын
Xd, it makes me feel a lot and a lot better that i was able to come up with greedy solution faster than errichto :D (but my was using a stack for keeping indexes of a stars, so it was linear space)
@ronaldabellano5643
@ronaldabellano5643 4 жыл бұрын
Ivan I thought same but took me an hour to make it work.
@spank2877
@spank2877 4 жыл бұрын
It took me around the same time... to understand the problem
@AAAAAA-gj2di
@AAAAAA-gj2di 2 жыл бұрын
@@spank2877 😳
@1098tony
@1098tony 4 жыл бұрын
I really enjoyed this video since it shows the thought process of top programmers such as Errichto when facing challenging problems.
@Deanin
@Deanin 4 жыл бұрын
"I'm stuck!" Haha, man that was a mood! The number of times I've had that exact reaction is just unreal. Keep up the great work, man. Always appreciate seeing how people react during these moments of uncertainty!
@algoseekee
@algoseekee 4 жыл бұрын
Explanations start at 19:47. That's clear now! Thanks, man!
@AdamSmith-du6us
@AdamSmith-du6us 4 жыл бұрын
awesome to see you struggle on one! making the rest of us feeling better.
@NikhilRaghav23
@NikhilRaghav23 4 жыл бұрын
Please do video explanation for matching parenthesis with different possibilities. And you are such a genuine person to tell that you struggled for this problem.
@adibhasan8114
@adibhasan8114 4 жыл бұрын
I SOLVED THIS USING A PAIR STACK and A STRING !!! THOUGH YOUR SOLUTION IS SO COOL ERRICHTO !!
@mohdar2061
@mohdar2061 4 жыл бұрын
Thanks. I was stuck trying to find a counting/replacing solution. I just couldn't think as deep as you did about the starts and the balance.. Keep it up!
@rooftoplin327
@rooftoplin327 4 жыл бұрын
Nneed to see the video more than once.Good job Errichto!
@anybody_y
@anybody_y 4 жыл бұрын
Great explanation Errichto, I started with an approach similarly using only balance and stars, but I couldn't solve it (because I never thought of checking from right to left) and past 30 min mark of struggle, I gave up on it and looked for solutions, and most of them looked somewhat different from this approach. Anyway, it's really great to see you solve it using this approach and in a way, it means I started correctly, just didn't finish it correctly.
@CarrotCakeMake
@CarrotCakeMake 4 жыл бұрын
I am always amazed at your ability to endure writing a program in a webpage textbox.
@namanbhayani1016
@namanbhayani1016 4 жыл бұрын
I couldn't solve this problem initially and I thought I was too dumb or something. If he's telling "I am stuck", I can now forgive myself :p Thanks for the explanation!!
@sebastianmestre8971
@sebastianmestre8971 4 жыл бұрын
I struggled with this one too. At first I tried something with stacks and some ad hoc logic, which didn't really work. Then I found the dp solution. All in all, it took me like 10 minutes.
@lovvyparhar393
@lovvyparhar393 4 жыл бұрын
one approach was to use stacks. First, ignore all the stars and cancel the parenthesis. Then keep the stars at appropriate positions along with the leftover brackets. Then go over this collection cancelling the leftover parenthesis with stars whenever possible. I am not sure why it works but it worked.
@jahongirrahmonov7323
@jahongirrahmonov7323 4 жыл бұрын
Although it is weird, I am glad that you struggled a little 😂 Loving the series. Keep it up!
@aditya8404
@aditya8404 4 жыл бұрын
I really like this video, because it helped me to think like you do, when i come across a problem and i don't have a solution, this was very insightful thank you :)
@raahelbaig8347
@raahelbaig8347 4 жыл бұрын
I feel so proud of the fact that I went through the exact same steps when coming to the same solution. I made the exact same mistakes while solving my solution as well XD XD
@oldman713
@oldman713 4 жыл бұрын
Please sir we will be really grateful if you make more lectures on parenthesis and their graph-like approach! Thank You!
@shubhamuniyal2417
@shubhamuniyal2417 4 жыл бұрын
By far the toughest one in 16 days,.. Errichto struggling means i did good if i completed it in 2 hrs. :D
@sakshisrivastava5596
@sakshisrivastava5596 4 жыл бұрын
I got annoyed while solving this problem and jump to discussion after like 30 mins. I regret that I should have also struggled more. Anyway, this video is really great and inspiring one. More lectures on these type of questions would be beneficial.
@ammsa7
@ammsa7 4 жыл бұрын
There’s also a DP and a single pass greedy algorithm. The single pass one is pretty nice and it’s only few lines of code (no reverse needed). I’m sure people would appreciate if you cover those as well.
@abdoulayediagne2976
@abdoulayediagne2976 4 жыл бұрын
I used a stack. Whenever you encounter a "(", you add it's index to the stack, and if it is a ")", you pop the stack if it's not empty and replace that bracket and the element at the removed index with "-" (or any other marking character); if it is empty, check if there's a star on it's left, and then replace both of them with "-". Finally, if there's remaining opening brackets, close them with the "*" on their right if it's possible (with the same method). In the end, if there is no remaining brackets on the string, then it's valid.
@abdoulayediagne2976
@abdoulayediagne2976 4 жыл бұрын
@@guerakun nope it's O(n) time, and O(n) space
@valcron-1000
@valcron-1000 4 жыл бұрын
0:15 HARD DISAGREE. I learn A LOT by watching someone else struggle. I can see what they tried first, what problems did they face and their journey to the correct answer. Defeat is the best teacher. Please don't remove the "struggle" part from any video!
@MikePrice888
@MikePrice888 4 жыл бұрын
Your solution is intuitive indeed. Thanks
@HIOLLJ
@HIOLLJ 4 жыл бұрын
This was doing my head in. Thanks for the elegant solution.
@ahsanulameensabit
@ahsanulameensabit 4 жыл бұрын
Great explanation....your approach is so helpful...
@atikshahriaranik5873
@atikshahriaranik5873 4 жыл бұрын
Yes, please make some videos about bracket sequences. And thanks for all your effort BTW.
@sagarverma7640
@sagarverma7640 4 жыл бұрын
Please cover the generic variants of parenthesis problems (stack, backtrack, DP/greedy etc.) as you mentioned in this lecture like the buy/sell Stocks one you already did previously..... it was really helpful :)
@PasselivreEdicoes
@PasselivreEdicoes 4 жыл бұрын
There's a really easy to code O(N²) dp solution. Just do dp[i][balance] where transitions is, well, add 1 to balance if you add a '(', subtract one from balance if add a ')' and you can do all three transitions if you add a "*" (go to dp[i+1][balance], dp[i+1][balance-1] or dp[i+1][balance]+1). Answer is dp[n][0]
@saiswaroop5889
@saiswaroop5889 4 жыл бұрын
I used recursion with memoization. I assumed each star can be converted into (empty, '(' or ')' ) and from there explored all scenarios. To reduce time consumed, i added memoization. Solution ran in 0 ms. if(ch=='(') a=a || dfs(li, i+1, c+1); else if(ch==')') a=a || dfs(li, i+1, c-1); else a=a || dfs(li, i+1, c) || dfs(li, i+1, c+1) || dfs(li, i+1, c-1); i = index in the string c = count of brackets ( if open +1, if close -1)
@rahil_rehan
@rahil_rehan 4 жыл бұрын
And memoisation?
@saiswaroop5889
@saiswaroop5889 4 жыл бұрын
@@rahil_rehan check this codeshare.io/2WRpxY
@JorgeIbanez713
@JorgeIbanez713 4 жыл бұрын
Why memoization actually works? What process you do multiple times?
@sangramjitchakraborty7845
@sangramjitchakraborty7845 4 жыл бұрын
Each time you found a * you branched into the three possibilities right? So how did you keep track of the no of brackets already explored? And what did you memoize? What are the overlapping subproblems here?
@MizardXYT
@MizardXYT 4 жыл бұрын
@@sangramjitchakraborty7845 Overlapping would be when having two or more stars. First star could decrease the balance, and the second could increase the balance. Same state would be achieved if first star would increase the balance, and second star would decrease it.
@mohitthorat8580
@mohitthorat8580 4 жыл бұрын
Hii, I implemented this with 2 stacks(parenthesis and stars). In both stacks I stored their indices. In parenthesis stack I only pushed opening brackets. Then iterated from left to right, false if current character is ')' and stack is empty and no of stars is 0. After that in end if my stack was not empty I converted stars whose indices were greater than opening brackets into closing brackets. If I couldn't do that then false.
@gladwinrojer273
@gladwinrojer273 4 жыл бұрын
Wow....that sounds like a great approach...did it work??
@mohitthorat8580
@mohitthorat8580 4 жыл бұрын
@@gladwinrojer273 Yes
@NotFound-hy7qb
@NotFound-hy7qb 4 жыл бұрын
Same because its from discussion
@jetblackjp
@jetblackjp 4 жыл бұрын
I did the EXACT same thing. Weird lol.
@nishantdas272
@nishantdas272 4 жыл бұрын
Hope that you make a video on such kind(parenthesis checker) of problem in future
@sharinganuser1539
@sharinganuser1539 4 жыл бұрын
one of those questions where ur eyes lights up the moment u read it.....but steadly u realise how cumbersome it is
@Anshul42
@Anshul42 4 жыл бұрын
It was really an interesting problem.. and there were so many different kinds of solutions.. from using brute force, to dp, to greedy, to using stacks, greedy, etc.
@tuhinmukherjee8141
@tuhinmukherjee8141 4 жыл бұрын
True. Even using dp, you can optimise the n^3 complexity to an n^2 complexity. But, later I went through the solutions to find out that there is an O(n) approach to this.
@RaoVenu
@RaoVenu 3 жыл бұрын
Errichto, is there a link to the follow up bracket sequences videos? When I saw this, I immediately thought of DP but your solution is so much better.
@liwaiyip1769
@liwaiyip1769 4 жыл бұрын
I really learnt a lot from your videos. Thank you!
@imranariffin2688
@imranariffin2688 4 жыл бұрын
Please do more of such a problem!
@YashSingh-ir3ec
@YashSingh-ir3ec 4 жыл бұрын
+1 for video tutorials like this problem.
@manmeetsingh1194
@manmeetsingh1194 4 жыл бұрын
yes, please provide a similar bracket matching problem explanation.
@thomi5562
@thomi5562 4 жыл бұрын
Nice video although you struggled :D I used a two pointer approach to get it working with only one iteration over each character, but the code is quite long and tricky. Your second solution is much shorter and better to understand.
@ananths5905
@ananths5905 4 жыл бұрын
Please make a lecture style video about paranthesis based thinking... would love to see this real soon from you
@sankalpramesh5478
@sankalpramesh5478 4 жыл бұрын
Please do make a video on such parenthesis or wherever such a graph is involved, with strategies to come up with a solution.
@L0Ls0ul
@L0Ls0ul 4 жыл бұрын
For me it's interesting that this particular problem was hard for you. I had more problems with earlier problems. I went through the string from front to back checking if number of "(" + "*" was greater or equal to number of ")" at all points. Then I did the same in reversed order while checking it for ")". That was a pretty straightforward O(n) time solution for me.
@L0Ls0ul
@L0Ls0ul 4 жыл бұрын
Update: I see that's what you did in the end as well.
@Errichto
@Errichto 4 жыл бұрын
But can you explain why it's correct? Why you won't try to change "*" into opening and closing bracket at the same time?
@L0Ls0ul
@L0Ls0ul 4 жыл бұрын
@@Errichto Yes, it's pretty much the same thought process. Going through the string the first time, you know that there are more "(" or "*" at each place in the string than ")", so you can satisfy "more "(" at all points than ")"". Going through the string the second time, you know that there are more ")" or "*" than "(", so you can conclude "more ")" at all points than "("". Hence you can conclude that there is a way to create an equality with stars but you can't tell which star represents which symbol (from the algorithm as it is since it's not constructive).
@venkateshthirunagiri85
@venkateshthirunagiri85 4 жыл бұрын
@@L0Ls0ul can you share your code?
@ГеоргийМай-т3в
@ГеоргийМай-т3в 4 жыл бұрын
I did the same thing almost immediately, but wasn't 100% sure it will be correct :| Still don't understand it intuitively
@hitesh155
@hitesh155 4 жыл бұрын
I too struggled for 20 mins 4 time wrong solution, later went on to use two separate stack - one for parentheses and one for count of stars from previous open parentheses
@vishalchaurasia96
@vishalchaurasia96 4 жыл бұрын
Errichto tell me some good resources which you use while learning Number Theory for Competitive Programming. I really need your suggestions.
@FazeelUsmani
@FazeelUsmani 4 жыл бұрын
Hey! Errichto, a video lecture on valid paratheses questions would be much appreciated.
@TarequeMdKhan
@TarequeMdKhan 4 жыл бұрын
Thanks for keeping the struggle part
@kabboghosh1853
@kabboghosh1853 4 жыл бұрын
what a humble person
@manjunathvasam4981
@manjunathvasam4981 4 жыл бұрын
Please upload lectures covering this topic of balancing brackets it would be very very helpful!!!
@sounishnath513
@sounishnath513 4 жыл бұрын
hey... how to split string in c++ in real quick if there are multiple delimiters ? for example Abhishek:34848,Mayur:4739,Friends:2949,Yeah:9889 , this is a string, where Mayur is a person name, and 4739 is an integer, and store it for future operation......
@faridgadzhiev1440
@faridgadzhiev1440 4 жыл бұрын
Hey Errichto, great video, as always! I also solved this in two passes in a similar way, but there's a neat one pass solution. Did you see it? Do you think it's possible (or needed) to find it under time pressure like an interview or a contest?
@jishnupramod2130
@jishnupramod2130 4 жыл бұрын
A series on patterns and bracket matching is very much appreciated :)
@yashpreetbathla4653
@yashpreetbathla4653 4 жыл бұрын
true CP , admitted that you struggle cheers man!
@varunmanchanda3972
@varunmanchanda3972 4 жыл бұрын
Yes please it will be very helpful if you make more videos on topic like balance parentheses.
@avi0gaur
@avi0gaur 4 жыл бұрын
Our thought process is bind with stack or balance counter based approch when it comes to check equation correctness. A small tuning of problem disturb that approach. I had to debug me code in IDE to make it. Poor me.
@ritwik-chakraborty
@ritwik-chakraborty 4 жыл бұрын
Yes erricto need videos on parenthesis balancing graph...
@nikhilwalmikpawar
@nikhilwalmikpawar 4 жыл бұрын
Yes please post a lecture video on this topic.
@mansuruddinkhan4001
@mansuruddinkhan4001 4 жыл бұрын
Lecture on such problem type would be great
@almuhimen8023
@almuhimen8023 4 жыл бұрын
Things are getting tough in leetcode, I think.
@barongrmel3797
@barongrmel3797 4 жыл бұрын
Todays is easy.
@Squirrelschaser
@Squirrelschaser 4 жыл бұрын
I thought of backtracking immediately and then got it working. I tried improving it with DP but I chose bad variables to record state, left paren counter and right paren counter, while the correct way for DP would have been a sum (single counter for left parent (+) and right paren (-)), and index. Couldn't figure out the O(N) time and O(1) space solution at all.
@SaadTaameOfficial
@SaadTaameOfficial 4 жыл бұрын
I think that it is beneficial to do more bracket problems to get exposed to different techniques of solving them.
@vivekraj1427
@vivekraj1427 4 жыл бұрын
Really need this topic from u do make one. Thanks for the explanation.
@openworld7585
@openworld7585 4 жыл бұрын
I love you Errichto
@pranaygarg1370
@pranaygarg1370 4 жыл бұрын
It would be really helpful if you make a video on bracket sequences.!
@Damoygames
@Damoygames 4 жыл бұрын
By looking to the solution of LeetCode, you can do it also in one pass using left and right integers. Here is their solution: def checkValidString(s): left = 0 right = 0 for c in s: left += 1 if c == '(' else -1 right += 1 if c != ')' else -1 if right < 0: break left = max(left, 0) return left == 0
@valcron-1000
@valcron-1000 4 жыл бұрын
I came up with a solution in Haskell. First, I implemented a function that checks if a "parenthesis expresion" is balanced - only '('and ')' characters - using a Stack. Then I added the '*' case: We can consider it a '(' or a ')' or we can just discard it - consider that it was never there in the first place. If I'm not mistaken this is in theory DFS. It's pretty small so I'll share it here: isBalanced :: [Char] -> Bool isBalanced str = go str [] where go (c : cs) stack | c == '(' = go cs (c : stack) -- Push a '(' into the Stack | c == ')' = if not (null stack) && head stack == '(' then go cs (tail stack) -- Keep going only if we can pop a '(' from the Stack else False | c == '*' = -- Special case for the "polymorphic" character go ('(' : cs) stack -- Assume is a '(' and keep going || go (')' : cs) stack -- Assume is a ')' and keep going || go cs stack -- Assume is a "ghost token" - ignore it - and keep going | otherwise = False -- Invalid char go [] stack = null stack -- If no characters left, check that the Stack is empty
@anubhavkumar3618
@anubhavkumar3618 4 жыл бұрын
very good explanation of problem :) hats off Can not we use recursion and backtracking on stack of parenthesis to solve the problem?? I got stuck while I was implementing it:(
@MizardXYT
@MizardXYT 4 жыл бұрын
My initial approach was to use a set of possible balances. '(' increased all balances, ')' decreased all balances, and '*' added -1, 0, and 1 to all balances simultaneously, growing the set. I later realized all the possible balances where continuous within a range, so I simplified the set to minBalance and maxBalance. int minBalance = 0, maxBalance = 0; foreach (var c in s) { if (c == '(') { minBalance++; maxBalance++; } else if (c == ')') { if (minBalance > 0) minBalance--; if (maxBalance == 0) return false; maxBalance--; } else if (c == '*') { if (minBalance > 0) minBalance--; maxBalance++; } } return minBalance == 0;
@ShengLUO
@ShengLUO 4 жыл бұрын
the reverse trick is cool
@israkulhaquetusher3256
@israkulhaquetusher3256 4 жыл бұрын
i have solved it using a pair under stack , my stack looks line stack < pair < char , int > > stack_name
@dmitrykarpenko2271
@dmitrykarpenko2271 4 жыл бұрын
When you go forward, star is considered to be a replacement for '('. Backward - only for ')'. Can you easily prove that the sets of stars used to replace '(' and to replace ')' will not intersect (e.g. we've not used an already used star)? (e.g. "from the contrary" proof might work, but I'm not completely sure)
@thomashirtz
@thomashirtz 4 жыл бұрын
Hey! Kinda curious, could you tell what software do you use to draw your schemes ?
@karanh
@karanh 4 жыл бұрын
great video!
@saifshaikh8055
@saifshaikh8055 4 жыл бұрын
Hey errichto, can you tell about DP approach for the problem.Thanks for such videos
@madhurimamondal9756
@madhurimamondal9756 4 жыл бұрын
Great ! Thanks a lot !
@PavanKumar-jt5mq
@PavanKumar-jt5mq 4 жыл бұрын
I could say this is the hardest problem for me until now. 😢
@robinli4610
@robinli4610 4 жыл бұрын
when you do the first loop, it seems that you want to find a opening bracket for every closing bracket(in this case, some '*' would be regarded as '(' ); And when you do the second loop, you want to find a closing bracket for every opening bracket(in this case, some '*' would be regarded as ')' ). And my question is how to prove that a character '*' would not be regarded as '(' and ')' to avoid contradiction in this two loops?
@ГеоргийМай-т3в
@ГеоргийМай-т3в 4 жыл бұрын
If we passed from left to right without replacing any * with '(' , then we pass from right to left and change the * without a doubt. Now let's suppose we changed some '*' on the first pass (from left to right), then there is the LAST star (if it is necessary, we change the stars starting from the left) that we changed. We changed it when we met the right bracket. We mentally note the entire prefix including this right bracket - this prefix is a correct parenthesis string. All stars to the end of expression are free. Now, when we go right to the left, we will have some free stars. We will check if it is possible to make a valid parenthesis string with these "free" stars for each step until we meet that noted prefix. if it is possible, we will reach the first member of "mentally noted" prefix - now it is suffix. We know for sure we will not try to change "*" into ')', because this suffix is correct parenthesis string. Please let me know if it is acceptable explanation
@robinli4610
@robinli4610 4 жыл бұрын
@@ГеоргийМай-т3в not clear much about "All stars to the end of expression are free. Now, when we go right to the left, we will have some free stars. We will check if it is possible to make a valid parenthesis string with these "free" stars for each step until we meet that noted prefix. if it is possible, we will reach the first member of "mentally noted" prefix - now it is suffix. We know for sure we will not try to change "*" into ')', because this suffix is correct parenthesis string."
@ГеоргийМай-т3в
@ГеоргийМай-т3в 4 жыл бұрын
@@robinli4610there are 3 options right after we finished the walk from the left to the end (first walk). 1) all the '*' were interpreted as '('. This way we have valid parenthesis prefix made of all the '*' : amount of '(' plus amount of '*' is equal to amount of ')' in this prefix. The remaining part of the line has no '*' symbol and every prefix of this part has more or equal '(' than ')'. While going from right to left we will find if the amounts were equal on every step. 2) none of the '*' were interpreted as '('. This case is trivial. 3) some of the '*' were interpreted as '(' . We can assume that all these '*' go in order (starting with first, then second etc.) because there's no point in letting a single or some '*'. This way we can throw this prefix away - prefix, where the amount of '(' plus amount of '*' is equal to amount of ')' . So now we have a suffix made of '(' , '*' , ')', where every prefix of this remaining suffix has more or equal '(' than ')' and all the '*' are "free" - it means we did not use them during the first walk as '(' . So the only thing to check is if on every step in walking from right to left the amount of ')' plus amount of '*' is not less than the amount of ')'.
@piyushjain5658
@piyushjain5658 4 жыл бұрын
Genuine video
@PasselivreEdicoes
@PasselivreEdicoes 4 жыл бұрын
Definitely hardest problem so far.
@MiketheCoder
@MiketheCoder 4 жыл бұрын
Errichto, can you do a vid about people cheating in competitive programming? Apparently a guy named Karan Gujar was cheating on codeforces and google code jam and bragged about his ratings on quora to get fame. Since you obviously worked very hard in competitive programming, what are your thoughts on this?
@VinayKumar-rq5kd
@VinayKumar-rq5kd 4 жыл бұрын
Please do videos on this more after this month.
@yyyooohhhooo
@yyyooohhhooo 4 жыл бұрын
Lecture on annoying bracket series would be great, Edward Snowden! I meant Errichto...
@ThomasSheppardPOB
@ThomasSheppardPOB 4 жыл бұрын
Hey Erric. At around 15 mins in you reference the array size being between 1,100 and say "DP was a intended solution here" can you explain what DP is?
@abdoulayediagne2976
@abdoulayediagne2976 4 жыл бұрын
Dynamic Programming. He made some videos on it.
LeetCode Day 17 - Number of Islands (Grid BFS Algorithm)
10:38
Errichto Algorithms
Рет қаралды 60 М.
Pro vs. Hard Coding Interview Problem - LRU Cache (LeetCode Day 24)
44:30
Errichto Algorithms
Рет қаралды 51 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 36 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 35 МЛН
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 7 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 93 МЛН
Valid parenthesis string | Leetcode #678
12:41
Techdose
Рет қаралды 52 М.
What Makes A Great Developer
27:12
ThePrimeTime
Рет қаралды 216 М.
Longest Common Subsequence - Recursive and Iterative DP (LeetCode Day 26)
19:44
Maximal Square of Ones (LeetCode Day 27)
12:08
Errichto Algorithms
Рет қаралды 40 М.
Programming with Math | The Lambda Calculus
21:48
Eyesomorphic
Рет қаралды 240 М.
LeetCode Day 15 - Product of Array Except Self
16:00
Errichto Algorithms
Рет қаралды 33 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 160 М.
Clean Code - Uncle Bob / Lesson 1
1:48:42
UnityCoin
Рет қаралды 1,9 МЛН
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 201 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 36 МЛН