Panda Guru LogoPanda
Guru

Google phone screen

Round 1

Questions: Given a string with +, - and parenthesis (only 1 level deep), we need to simplify the expression. For example:

a+b+a+c-b-b-b+(d+c) => 2a-2b+2c+d
Candidate's Approach
  • Implemented a single pass solution while keeping a flag to track "-(".
  • Used the flag to check each operand sign and added to a hashmap.
  • Later traversed the hashmap to print each single variable with its count.
  • Missed to print '+' in the last string, as the focus was only on negative operations.
  • Did not get to dry run the code due to time constraints.
Interviewer's Feedback
  • Suggested adding a comment //Need to address '+' addition in result above the line where the check needs to happen.