I want this in Python, it available in but too complicated | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I want this in Python, it available in but too complicated

Simplify a given algebraic string of characters, ‘+’, ‘-‘ operators and parentheses. Output the simplified string without parentheses. Examples: Input : "a-(b+c)" Output : "a-b-c" Input : "a-(b-c-(d+e))-f" Output : "a-b+c+d+e-f" I tried https://code.sololearn.com/cPiHvUryJoVI/?ref=app

18th Nov 2018, 8:48 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
9 Answers
+ 7
https://code.sololearn.com/cRG0HYE7Ed3z/?ref=app
18th Nov 2018, 10:05 AM
Mert Yazıcı
Mert Yazıcı - avatar
+ 5
Well, it _is_ a bit complicated. For the second input, how would you do it "by hand"? What if it had even more nestings? Have you tried turning that idea into a code? Your code doesn't seem to show any indication of changing the signs at all!
18th Nov 2018, 9:07 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
Have a look at my explanation. It's heavily commented but in Javascript because I shouldn't give you the solution too directly, in order for you to still enjoy the learning experience. https://code.sololearn.com/Wm0W9mc3e60p/#js
18th Nov 2018, 10:15 AM
Gabriel Vasile
Gabriel Vasile - avatar
+ 4
Dhairyashil Deshpande well I don't know what "high level" means to you, but you shouldn't really expect what you wrote in your code to do the job as asked. Try to think the problem through. Do some examples, formulate a strategy, and then try to code it. And if you're feeling lazy, I can't stop you from cheating and looking at Gabriel's code! 😉
18th Nov 2018, 11:52 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Besides the explanation giving earlier I should also say that this puzzle might be a bit too complicated for a beginner. It's possible you might need to start small, with easier puzzles. One website that can make the transition from easy to harder solving puzzles is edabit.com
18th Nov 2018, 12:01 PM
Gabriel Vasile
Gabriel Vasile - avatar
+ 3
You can do it, we believe in you! 😊 If it looks too hard, do some intermediate problems first, as Gabriel suggested. Then try a simpler variant of this one (say, with only one pair of parentheses). If you get stuck, show your attempt, and we'd be happy to provide more hints. Good luck! :)
18th Nov 2018, 3:03 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
thanks I will check it out, I know this code was way out of my league but still I wanted to know the answer for the question asked in the test. It was a placement test for a big IT company
18th Nov 2018, 2:37 PM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
0
I don't understand, is it a high level coding question? It was asked in an aptitude test for placement in Wipro
18th Nov 2018, 9:55 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar