Google Phone Interview
Anonymous User
768

There are 2 questions: the first one was easy but the second one was hard for me.
The general idea of question 2 is like designing a function that receives a string containing of 2 different commands: add (for addition) and sub (for subtraction). That function should return an integer.
For example:
"add(add(2,2),add(2,2))" -> 8
"add(sub(-1,3),add(25,2))" -> 23
"add(sub(-1,3),4)" -> 0
"sub(1,add(1,sub(1,1)))" -> 0

Any idea how to solve this problem? I've been struggling with it for a day. Also, if the commands do not have the same length (i.e., multiple, addition, subtraction, division), what should I do?

Comments (3)