Panda Guru LogoPanda
Guru

Uber Phone Screen | Basic Calculator (Variation)

Round 1

Questions: This is a variation on the Basic Calculator where we essentially are thinking about parsing the input in a pre-order manner [sign, operand1, operand2].

Input/Output Examples:

# Parse strings that for a simple language as follows : # input -> "add(1,3)" output -> 4 # input -> "sub(1,3)" output -> -2 # Input -> “add(3, add(3, 2))” -> 8 # Input -> “ add(3, sub(3, add(3, 2))) ” -> 1 # Input -> “add( bad,2342)” -> return exception “syntax error at position 6 for "bad" in the string”
Candidate's Approach
  • Came super close to a working solution with a few bugs.
  • Time Complexity: O(n)
  • Space Complexity: O(n)

The candidate implemented a solution using two stacks to handle the signs and operands. The approach involved parsing the string character by character, handling digits, operators, and parentheses accordingly.

Interviewer's Feedback

No feedback provided.