← Rokt Interview Insights

Rokt·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Interviewed for a software engineering role at Rokt and got a classic expression evaluator problem. Not the hardest thing in the world but there are enough edge cases to trip you up if you're not careful about operator precedence.

Questions Asked (1)

Q1

Implement a function that evaluates a basic arithmetic expression string containing non-negative integers and the operators +, -, *, /. Spaces should be ignored, division truncates toward zero, and there are no parentheses.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The precedence handling is where people mess up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then propose a two-pass stack-based approach that handles operator precedence and left-to-right evaluation. Walk through an example to demonstrate correctness, and discuss time/space complexity and potential trade-offs.

Pro tip: Mention that you can avoid using a stack by first tokenizing and then evaluating with two passes, but highlight that the stack approach is more extensible for adding parentheses or more operators. Also, explicitly handle division truncation toward zero, especially for negative intermediate results (though inputs are non-negative, intermediate results can be negative).

1. Clarify requirements and edge cases

Ask about input format, possible edge cases (e.g., empty string, single number, multiple spaces, division by zero), and confirm that division truncates toward zero. Discuss how to handle negative intermediate results.

2. Choose an approach

Propose a stack-based solution: parse the string, maintain a current number and a last operator, and use a stack to handle precedence. Alternatively, mention a two-pass approach (first handle * and /, then + and -) but note its limitations.

3. Walk through the algorithm

Explain step-by-step: iterate through characters, build multi-digit numbers, when an operator is encountered, apply the previous operator to the current number and the top of the stack (or push/pop accordingly), then update the operator. At the end, sum the stack.

4. Analyze complexity and trade-offs

State that time complexity is O(n) and space complexity is O(n) for the stack. Discuss trade-offs: stack uses extra space but simplifies precedence; two-pass avoids stack but requires more parsing logic and is less extensible.

5. Test with examples

Walk through a sample expression like '3+2*2' to show how the stack evolves, and mention testing edge cases like '14-3/2' (truncation) and ' 3/2 ' (spaces).

Key Points to Mention

  • Operator precedence: multiplication and division before addition and subtraction.
  • Handling multi-digit numbers and ignoring spaces.
  • Division truncation toward zero (e.g., 3/2 = 1, -3/2 = -1).
  • Using a stack to store intermediate results and apply operators.
  • Time and space complexity: O(n) time, O(n) space.
  • Edge cases: empty string, single number, division by zero (if allowed), and negative intermediate results.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.