Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.
19th May 2020, 2:16 PM
Lothar
Lothar - avatar
+ 6
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I think I am correct at very first saying to use the "stack concept"... https://code.sololearn.com/cvI32jf6MULA/?ref=app
15th May 2020, 3:21 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 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
15th May 2020, 2:27 PM
Oma Falk
Oma Falk - avatar
15th May 2020, 2:29 PM
Abhay
Abhay - avatar
+ 4
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 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"
15th May 2020, 2:33 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 U can use "stack". It's a hint for the solution
15th May 2020, 2:23 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 3
Kiran Deep Naidu very good hint!
15th May 2020, 3:20 PM
Oma Falk
Oma Falk - avatar
15th May 2020, 2:43 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 I would suggest another solution that is split the string to half and check whether all are properly enclosed
15th May 2020, 2:46 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Oh is it, let me also make a try...
15th May 2020, 2:48 PM
Kiran Deep Naidu
Kiran Deep Naidu - avatar
+ 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.
16th May 2020, 10:13 PM
rodwynnejones
rodwynnejones - avatar
+ 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
17th May 2020, 4:22 AM
Humayun Ali Khan
Humayun Ali Khan - avatar
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 that line is ur u U can add user input option if u want
15th May 2020, 2:30 PM
Abhay
Abhay - avatar
+ 1
https://www.sololearn.com/post/404171/?ref=app Check out this ☝👆☝👆☝
15th May 2020, 2:40 PM
Abhay
Abhay - avatar
+ 1
May be their are more brackets or an non bracket string And one more logic to check for absence of any bracket
15th May 2020, 2:43 PM
Abhay
Abhay - avatar
+ 1
Good
17th May 2020, 6:28 AM
Nina Hendra Putri
Nina Hendra Putri - avatar
0
Ur q. Is so simple is it a challenge
15th May 2020, 2:32 PM
Abhay
Abhay - avatar
0
Kiran Deep Naidu it is saying no what is ur problem
15th May 2020, 2:37 PM
Abhay
Abhay - avatar
0
Just find the length of string , if it is even then, yes
16th May 2020, 4:37 AM
Rohit Gupta
Rohit Gupta - avatar