Google Interview Question {Data structure}, 7yoe
Anonymous User
1367

I was asked following question in one round of google.
given a string that contains only two possible operations "add", "sub". Evaluate and print integer value.Nesting can be any level
If the string is invalid, print "invalid input"
Input:
add(sub(3,2),add(1,2))
Output
4
Input
adde(1,4)
Output
"Invalid input"
Input
adde(1,4
Output
"Invalid input"

My approach: tried to do it via recusrion, able to write code when input string is valid. He wanted to handle validation in the recusrion itself.
Any suggestions

Comments (3)