is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
To solve this problem we can check if the string is balanced without take into account the stars. During the check we'll store the open parenthesis position in a stack and when we find a close parenthesis we extract the matching one (the open parenthesis) from the stack and replece both position on the string with empty string. This way if the string is already balanced the fina string will has only stars or nothing. If the string isn't balanced we will get a pattern where the close parenthesis are at left of the open parenthesis, something like this:
*))**))))***((((****((((****
Note: this pattern can have how many stars and parenthesis how we wish, but the condition previously mentioned will apply always (all close parenthesis are on the left of open parenthesis).
Now, we can iterate this string from left to right and assume the stars are open parenthesis until we get a real open parenthesis. We can have a counter to increment it when a star is recognize and decrement it when we find a close parenthesis. If we found a open parenthesis we reset the counter and start again but from the end of the string until the position of the first open parenthesis, again we increment the counter on stars and decrement on open parenthesis. If in any case during the iterations the counter gets a value < 0 we can say the string is balanced. This is the code:
- leobelizquierdo October 25, 2017