New course! Every coder should learn Generative AI!
Try a free lesson+ 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.
+ 6
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
I think I am correct at very first saying to use the "stack concept"...
https://code.sololearn.com/cvI32jf6MULA/?ref=app
+ 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
+ 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"
+ 3
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
U can use "stack". It's a hint for the solution
+ 3
Kiran Deep Naidu very good hint!
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Sorry it was mistaken
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥
I would suggest another solution that is split the string to half and check whether all are properly enclosed
+ 2
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 Oh is it, let me also make a try...
+ 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
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 that line is ur u
U can add user input option if u want
+ 1
https://www.sololearn.com/post/404171/?ref=app
Check out this ☝👆☝👆☝
+ 1
May be their are more brackets or an non bracket string
And one more logic to check for absence of any bracket
+ 1
Good
0
Ur q. Is so simple is it a challenge
0
Kiran Deep Naidu it is saying no what is ur problem
0
Just find the length of string , if it is even then, yes