The Game of Brackets | SoloLearn: Learn to code for FREE!

+7

The Game of Brackets

In a code editor you need to indent the code and color the closing parenthesis of a selected parenthesis, to know the code block and if there are unequal number of paranthesis, there must be something wrong, ie every opening brackets/paranthesis should be having closing brackets/paranthesis. This problem is scaled down version, you are given a string and you need to tell is it valid or not, based on the facts stated above. ------------------------------------------------------------- Input Input contains a string Sample Input [[{{()}}}]] ------------------------------------------------------------- Output Print "Yes" for a valid string, else "No", without quotes. Examples: {{[]}} : Yes {[}] :No [[]) : No {}([]) : Yes ------------------------------------------------------------- Sample Output Yes Plz give me ONLY hints to solve this problem

33 Answers

New Answer

+9

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 what's the problem? https://code.sololearn.com/cD6TEwOCacqA/?ref=app

+7

????? ??????, i would like to share some hints with you to solve the bracket challenge in a very simple way. What we are going to do is, to use the string that contains all the brackets, and try to find 3 patterns: - () - [] - {} For all this three pairs we can be sure (if we find them), that they can be removed from the string. This first iteartions can be done in a for loop. After each loop we have to check, if a removing was done. So the iteration has to be run as long as you can find pairs. If yes, the next iteration with the 3 pairs has to be repeated. To control if a furtheriteration has to be done, a while loop can be used. If no more replacement can be done in the for loop, processing is finished. If the string is empty now, brackets has been ok, if there any elements are in the string, these could not be solved, this means that brackts are not ballanced. Happy coding.

+5

Find where to opening directly follows a closing. Remove both. Go on until string is empty.if u cant remove all brackets, game over

+5

For soln https://code.sololearn.com/cIZjvTougUI3/?ref=app

+5

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I think I am correct at very first saying to use the "stack concept"... https://code.sololearn.com/cvI32jf6MULA/?ref=app

+3

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 In line 4 the input was "[[])" and if you does as what Oma Falk said the elements remaining would be ["["]. So, as it is not empty it returns "No"

+3

Kiran Deep Naidu Yeah I have done it also But as I've told you about {}([]), it's creating problem if I split it into half, {}( []) which are not same

+3

Kiran Deep Naidu very good hint!

+3

Jay Matthews thanks for your concern, but it's not an assignment, I'm using Dcoder from 1 week & completing the tasks given in the app Where I do not understand the question or need some hints , I ask here for help

+2

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 U can use "stack". It's a hint for the solution

+2

Can't you just loop over the string and use e.g mystring = mystring.replace("()", '') and do the same for the "{} and the "[]"? Each pair will then be removed until only the none-pairs are left. edit...I've had a go and it seems to output correctly using your examples inputs.

+2

Find where to opening directly follows a closing. Remove both. Go on until string is empty.if u cant remove all brackets, game over

+2

Humayun Ali Khan thanks for your concern

+1

Oma Falk I was also thinking this one, but check 4 line in example

+1

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 that line is ur u U can add user input option if u want

+1

Abhay plz check whole question Did you find any word challenge & also your code passed 3 out 4 cases not last one

+1

Kiran Deep Naidu M asking about {}([])

+1

https://www.sololearn.com/post/404171/?ref=app Check out this ☝👆☝👆☝

+1

Abhay I understood your logic but the problem your code only passed my 3 cases not the last one

+1

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Sorry it was mistaken