-
-
Notifications
You must be signed in to change notification settings - Fork 120
[CONTENT] Solve this problem and write out a solution for it. (or make a video) #277
Comments
can you assign this to me? |
The solution should be language-specific like python or is it ok with any language? |
it's ok with any language! if we have solutions in multiple languages, it'd be even cooler I think |
@ykdojo sir , I fixed the issue |
@Akshay1018 by the way, the question is much harder when there's the "update" option instead of just delete and add. Any thoughts about it? Should it be phrased in a two-stage way? |
@ykdojo Right, this question is hard because we need to return the minimum operations based on two conditions. Let's talk about the conceptual overview. I will take an example and try to return minimum operations. intuition-1 we can add two parentheses at last and our total operation to make it valid will be 2 right? intuition-2 Please observe we can replace the second index with closed parentheses and our total operation to make it valid will be only 1. If we take a minimum of both the 2nd intuition will be returned {Math.min(2,1)} We can approach this using Dynamic programming and we need to take care of edge cases, like when to use the operation to return the minimum. |
@ykdojo any thoughts on this? |
@Akshay1018 I'll get back to you! I didn't have a chance to respond here yet |
@ykdojo cool! Take your time. Thanks. |
Are you saying we need to return an integer from this function? Because if that's the case, the problem would be much easier, and honestly more realistic as an interview question.
"when to use the operation to return the minimum" ^Can you clarify what you mean by that exactly? Other than that:
This sounds good! |
@ykdojo When we get the minimum number of operations to solve this problem then we can easily create the valid parenthesis using backtracking. minimum operations (n) = 1 output = (()) or ()() is this sounds good? |
I can say this is two step process/solution:
|
Sounds good. I think we can split it into two problems then, if it's with you. The first problem will ask you to output the min # operations. The second one, with the same setup, will ask you to output a list (or a set) of end-state valid parenthesis strings. |
Exactly, we can say the second one is |
@Akshay1018 sounds good! I'll start working on solving it, then. Feel free to start writing a solution for it if you'd still like to, as well. |
@ykdojo Sure, I'll write and update ASAP. |
@Akshay1018 cool, thank you so much! |
Brute Force Solution: Step 1 counts a minimum number of operations to make parenthesis valid. `class Solution {
}` |
Step -2 Generate Valid parenthesis with minimum count and return the result class Solution { |
@ykdojo Please check this solution. This is a brute force approach, we can optimize this solution, and let me know your thoughts on it. Thanks. |
@Akshay1018 thank you! I'll check it soon |
@ykdojo sure, please check on this and we will come up with an optimized solution. |
here is my solution full code with test cases checker
|
Description
One of the approved questions we have was recently asked by Google, and it is this:
It'll be good to have a solution for this so we can display it on the website, and so we can make a video out of it.
The text was updated successfully, but these errors were encountered: