← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Meta software engineering interview, two algorithmic problems back to back with a follow-up discussion tacked on at the end. Both problems were meaty enough that the session felt pretty compressed. Not a lot of small talk.

Questions Asked (3)

Q1

Given a permutation of integers, rearrange it in-place to produce the next permutation in lexicographic order. If none exists, wrap around to the smallest ordering. Aim for O(n) time and O(1) space, and walk through the algorithm and edge cases.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the algorithm but explaining the 'why' behind each step while coding at the same time was harder than expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then explain the three-step algorithm: find the pivot (first decreasing element from the right), find the successor (smallest element greater than pivot to its right), and reverse the suffix. Emphasize that this achieves O(n) time and O(1) space, and discuss handling wrap-around and duplicates.

Pro tip: Mention that the algorithm is exactly what C++'s std::next_permutation uses, and that the reverse step is crucial for minimizing the suffix. Also, proactively discuss how to handle duplicates and the wrap-around case by reversing the entire array.

1. Clarify and Confirm

Restate the problem, confirm input/output format, and ask about edge cases like empty array, single element, duplicates, and wrap-around behavior.

2. Identify the Pivot

Scan from right to left to find the first index i where nums[i] < nums[i+1]. If no such index exists, the array is in descending order, so reverse the entire array to get the smallest permutation.

3. Find the Successor

From the right, find the first element nums[j] that is greater than nums[i]. Swap nums[i] and nums[j].

4. Reverse the Suffix

Reverse the subarray from i+1 to the end to get the smallest possible suffix, ensuring the next permutation is the immediate next in lexicographic order.

5. Analyze Complexity and Edge Cases

Explain that each step is O(n) time and O(1) space, and discuss edge cases: empty array, single element, all equal elements, and wrap-around.

Key Points to Mention

  • Time complexity O(n) and space complexity O(1) with in-place operations.
  • The pivot is the first element from the right that is smaller than its right neighbor.
  • If no pivot exists, reverse the entire array to wrap around to the smallest permutation.
  • The successor is the smallest element greater than the pivot to its right; swapping them maintains order.
  • Reversing the suffix after the pivot is essential to get the next permutation, not just any larger one.
  • Handling duplicates: the algorithm still works because we look for strict inequality when finding the pivot and successor.

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

Q2

Implement a basic arithmetic expression evaluator for strings containing non-negative integers and the operators +, -, *, /. No parentheses, spaces may appear. Return an integer result using truncation toward zero for division. Target O(n) time and constant space.

Algorithms & Data Structures
Author's notes

The division truncation toward zero tripped me up briefly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a single left-to-right pass with a stack to handle operator precedence: accumulate terms for addition/subtraction, and for multiplication/division, apply the operator to the last term in the stack. This yields O(n) time and O(1) space if you use a running total and last term instead of a stack.

Pro tip: Clarify edge cases upfront: division truncation toward zero (e.g., -3/2 = -1), handling of spaces, and potential integer overflow. Also, mention that you can avoid a stack by maintaining a running sum and a last term, which keeps space constant.

1. Clarify requirements and edge cases

Confirm input constraints: non-negative integers, operators +, -, *, /, no parentheses, spaces allowed. Ask about division truncation (toward zero) and integer overflow handling.

2. Choose the right data structure

Decide between a stack-based approach (O(n) space) or a constant-space approach using a running total and last term. For Meta, aim for constant space to impress.

3. Parse and evaluate in one pass

Iterate through the string, building numbers and applying operators. For + and -, push the signed number to the stack (or add to running total). For * and /, pop the last number, apply the operator, and push the result back.

4. Handle division truncation and spaces

Implement integer division that truncates toward zero (e.g., using Math.trunc or casting to int after division). Skip spaces during parsing.

5. Test with edge cases

Test with expressions like '3+2*2', ' 3/2 ', '3+5 / 2', and negative results. Verify O(n) time and O(1) space.

Key Points to Mention

  • Operator precedence: multiplication and division have higher precedence than addition and subtraction.
  • Stack-based evaluation for precedence, or constant-space variant using running total and last term.
  • Integer division truncation toward zero (e.g., -3/2 = -1).
  • Handling spaces by skipping them during parsing.
  • Time complexity O(n) and space complexity O(1) if using constant-space approach.
  • Edge cases: single number, leading/trailing spaces, division by zero (though not specified, mention it).

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

Q3

Discussion only: how would you extend the evaluator to handle parentheses and correctly evaluate nested expressions with proper operator precedence?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Pure discussion, no coding.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the current evaluator's design and assumptions, then propose a two-stack or recursive descent approach to handle parentheses and precedence. Explain how you would modify the tokenizer and parser to support nested expressions, and discuss trade-offs between different parsing strategies.

Pro tip: Mention that you would first check if the existing evaluator uses a simple left-to-right evaluation, and then highlight that adding parentheses often requires a shift to a proper parsing algorithm like shunting-yard or recursive descent, which also naturally handles precedence.

1. Clarify current evaluator

Ask about the existing evaluator's architecture: does it use a simple loop, a stack, or a parser? Understand its limitations with parentheses and precedence.

2. Choose parsing strategy

Decide between algorithms like shunting-yard (two stacks) or recursive descent. Consider factors like ease of implementation, extensibility, and performance.

3. Handle parentheses and precedence

Explain how the chosen algorithm processes parentheses (e.g., pushing/popping on stack or recursive calls) and enforces operator precedence (e.g., via precedence table or grammar rules).

4. Discuss trade-offs and edge cases

Compare approaches in terms of time/space complexity, code complexity, and error handling (e.g., mismatched parentheses, invalid expressions).

5. Summarize and test

Outline how you would test the extended evaluator with nested expressions and mixed operators, and mention potential optimizations or extensions.

Key Points to Mention

  • Two-stack algorithm (shunting-yard) for infix to postfix conversion
  • Recursive descent parsing with grammar rules for expression, term, factor
  • Operator precedence and associativity handling
  • Parentheses matching and error detection
  • Time and space complexity of different approaches
  • Extensibility to support functions, unary operators, or variables

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