We can solve above problem using stack. But we can use eval from python 2 library also to solve this question. Thanks to sonu628 for this idea. But unfortunately this solution gives Runtime Error(RE) for second test and Accepted for first test. Can we fix this?