← Meta Interview Insights

Meta·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Four algorithm problems back to back at Meta for a software engineer role. Nothing behavioral, just pure coding the whole time. The problems ranged from pretty standard to genuinely annoying under pressure.

Questions Asked (4)

Q1

Given a string with non-negative integers, '+', and '*' operators (and optional spaces or commas), evaluate the expression respecting standard operator precedence (multiplication before addition), in O(n) time.

Algorithms & Data Structures
Author's notes

This one tripped me up more than it should have.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify input format and constraints, then propose a single-pass O(n) algorithm using a stack or running sum with a pending multiplication term. Walk through the algorithm with a small example, and discuss edge cases like leading/trailing operators and spaces.

Pro tip: Mention that you can avoid a stack by maintaining a running total and a current term for multiplication, which uses O(1) space and is more efficient. This shows you optimize beyond the basic stack solution.

1. Clarify requirements and constraints

Ask about input format (spaces, commas), whether the expression is always valid, and if negative numbers are possible. Confirm that O(n) time and O(1) space are desired.

2. Outline the algorithm

Explain that you'll parse the string left to right, maintaining a running total and a current term for multiplication. When you see '+', add the current term to the total and reset; when you see '*', multiply the current term by the next number.

3. Walk through an example

Trace the algorithm on a sample input like '3+2*2' to demonstrate how it respects precedence and yields the correct result (7).

4. Discuss edge cases and complexity

Cover cases like multiple-digit numbers, spaces, and expressions starting with a number. State that time complexity is O(n) and space is O(1).

5. Write clean code

Implement the solution with clear variable names and handle parsing carefully. Test with a few cases if time permits.

Key Points to Mention

  • Single-pass parsing with a running total and current term for multiplication
  • Handling of multi-digit numbers and optional spaces/commas
  • Operator precedence: multiplication before addition
  • O(n) time complexity and O(1) space complexity
  • Edge cases: leading/trailing operators, empty string, invalid input
  • Comparison with stack-based approach and why the running sum method is better

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

Q2

Given a sorted array of integers and a target value, return how many times the target appears. Must run in O(log n) time using binary search.

Algorithms & Data Structures
Author's notes

Easiest one of the four.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use binary search to find the first and last occurrence of the target, then return the difference plus one. This achieves O(log n) time by performing two modified binary searches. Alternatively, find any occurrence and expand, but that could be O(n) in worst case, so the two-boundary approach is preferred.

Pro tip: Mention that you can optimize by searching for the target+0.5 and target-0.5 to find insertion points, but clarify that this only works for integers. Also, discuss edge cases like empty array or target not present.

1. Clarify and Confirm

Restate the problem to ensure understanding: sorted array, target value, return count, O(log n) requirement. Ask about duplicates, data types, and edge cases.

2. Outline Approach

Explain that you'll use binary search to find the first and last index of the target. If not found, return 0. Otherwise, count = last - first + 1.

3. Implement Binary Search for Boundaries

Write a helper function for binary search that finds the first occurrence (leftmost) and another for the last occurrence (rightmost). Adjust mid calculation and conditions to continue searching even after finding the target.

4. Handle Edge Cases and Complexity

Check for empty array, target not present, all elements same. Analyze time complexity: O(log n) for each search, so O(log n) total. Space complexity O(1).

5. Test with Examples

Walk through a few examples: target present multiple times, once, not at all. Verify the code logic and boundary conditions.

Key Points to Mention

  • Binary search modification to find first and last occurrence
  • Time complexity O(log n) and space complexity O(1)
  • Edge cases: empty array, target not found, all elements equal to target
  • Avoid linear scan after finding one occurrence
  • Use of mid = left + (right - left) // 2 to prevent overflow
  • Return count as last - first + 1 if found, else 0

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

Q3

Given a sorted list of integers in [0, 99] that are present, output all missing values in that range as formatted strings: runs of 3 or more missing numbers as 'a->b', shorter runs listed individually as comma-separated values.

Algorithms & Data Structures
Author's notes

The formatting rule is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then design a linear scan that tracks consecutive missing numbers and formats runs of length >=3 as ranges. Implement and test with examples, ensuring O(n) time and O(1) extra space.

Pro tip: Mention that you can avoid extra space by scanning the sorted list and using the gap between consecutive present numbers to identify missing runs, and handle the boundaries (0 and 99) explicitly.

1. Clarify requirements and edge cases

Ask about input format, whether the list is guaranteed sorted and unique, and how to handle empty lists or full ranges. Confirm the exact output format for runs and individual numbers.

2. Design the algorithm

Use a linear scan: iterate through the sorted list, and for each gap between consecutive present numbers (including before the first and after the last), collect the missing numbers. Format runs of length >=3 as 'a->b' and shorter runs as comma-separated values.

3. Implement with careful boundary handling

Initialize a pointer to 0. For each number in the list, if it's greater than the pointer, the missing numbers are from pointer to number-1. After the loop, handle missing numbers from pointer to 99. Use a helper to format a range of missing numbers.

4. Test with examples and edge cases

Test with cases like empty list, full list, single missing number, run of exactly 3, run at the start or end, and multiple runs. Verify output matches expected format.

5. Analyze complexity and discuss optimizations

State that the solution is O(n) time and O(1) extra space (excluding output). Discuss potential variations, such as handling unsorted input or different ranges.

Key Points to Mention

  • Linear scan with O(n) time complexity
  • Constant extra space (O(1)) excluding output
  • Handling boundaries: missing numbers before first element and after last element
  • Formatting runs: exactly 3 or more missing numbers as 'a->b', otherwise individual numbers
  • Edge cases: empty list, full list, single missing number, run at start/end
  • Clarifying questions: sorted? unique? inclusive range? output format details

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

Q4

Find the minimum window substring of s that contains all characters of t with their required frequencies. Return an empty string if no such window exists. Target O(|s|) time with a sliding window approach.

Algorithms & Data Structures
Author's notes

Classic sliding window and I knew the pattern going in, but I fumbled the condition for shrinking the window.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a sliding window with two pointers to expand and contract the window while maintaining character counts. Track the number of characters that have met their required frequency to know when the window is valid. When valid, shrink the window from the left to find the minimum length, updating the result accordingly.

Pro tip: Clarify edge cases upfront (e.g., empty strings, characters not in t) and discuss how you'd handle Unicode or large character sets. Mention that the algorithm runs in O(|s| + |t|) time and O(k) space, where k is the number of unique characters in t.

1. Understand the problem and edge cases

Restate the problem to ensure clarity: find the smallest substring of s containing all characters of t with exact frequencies. Discuss edge cases like empty s or t, or when t has characters not in s.

2. Choose data structures

Use a hash map (or array for ASCII) to store the required frequency of each character in t. Use another hash map to store the frequency of characters in the current window.

3. Implement sliding window

Initialize left and right pointers at 0. Expand right to include characters, updating the window frequency and a counter for how many characters have met the required frequency. When all characters are satisfied, shrink the window from the left while maintaining validity, updating the minimum length and start index.

4. Track and return result

Keep track of the minimum window length and its starting index. After the loop, return the substring if found, otherwise return an empty string.

5. Analyze complexity and test

Explain that the time complexity is O(|s| + |t|) because each character is visited at most twice, and space is O(k) where k is the number of unique characters in t. Walk through a small example to verify correctness.

Key Points to Mention

  • Sliding window technique with two pointers (left and right) to expand and contract the window.
  • Use of frequency maps (hash map or array) to track required and current character counts.
  • Maintaining a 'formed' counter to efficiently check when the window contains all required characters.
  • Shrinking the window from the left when valid to find the minimum length.
  • Time complexity O(|s| + |t|) and space complexity O(k) where k is unique characters in t.
  • Handling edge cases such as empty strings or when no valid window exists.

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