← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Meta SWE coding round, one algorithmic problem about building target sums by inserting operators between numbers. Pretty focused session, just the one problem but with enough depth to keep you busy.

Questions Asked (1)

Q1

Given a list of integers and a target value, find how many ways you can insert '+' or '-' operators between the numbers (or no operator at all, treating adjacent numbers as concatenated) to reach the target sum.

Algorithms & Data Structures
Author's notes

The 'no operator' part is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify that this is a variation of the 'Target Sum' problem where concatenation is allowed, which adds complexity. Use recursion with memoization (DP) to explore all possibilities: at each step, either concatenate the current number with the next, or apply '+' or '-' and move to the next number. Track the current index, current sum, and previous operand to handle concatenation correctly.

Pro tip: Mention that without concatenation, the problem can be solved with subset sum DP, but concatenation makes it a stateful DFS. Also, discuss potential optimizations like pruning when the remaining maximum possible sum can't reach the target.

1. Clarify the problem

Confirm that concatenation is allowed and that numbers are used in the given order. Ask about constraints (e.g., list size, number ranges) to determine if exponential brute force is acceptable.

2. Define recursive function

Define a function dfs(index, current_sum, previous_operand) that processes the list from index onward. At each step, decide whether to concatenate the next number to the previous operand or to apply '+' or '-'.

3. Handle concatenation

When concatenating, update the previous operand by multiplying by 10 and adding the new digit, and adjust the current sum accordingly. This requires tracking the last operand's value and its sign.

4. Apply memoization

Use a memo table (e.g., HashMap) keyed by (index, current_sum, previous_operand) to avoid recomputing overlapping subproblems. Note that previous_operand can be large, so consider using a string key or limiting memoization.

5. Analyze complexity and edge cases

Discuss time complexity (exponential without memo, but memoization reduces it) and space complexity. Handle edge cases like empty list, single number, and leading zeros in concatenation.

Key Points to Mention

  • This is a variation of the classic 'Target Sum' problem with concatenation, which increases branching factor.
  • Recursion with memoization is suitable; state includes index, current sum, and last operand value.
  • Concatenation requires careful handling of the last operand's contribution to the sum.
  • Without concatenation, subset sum DP works, but concatenation breaks the simple DP due to state dependency.
  • Pruning: if the maximum possible sum from remaining numbers (all positive) is less than target, prune.
  • Edge cases: leading zeros in concatenation (e.g., '05' is just 5), and empty list.

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