← Meta Interview Insights

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

SeniorPrefer not to say
Jul 2026

Summary

Four independent coding problems in what felt like a Meta onsite coding round. The problems ranged from a grid simulation to a segment tracking problem to something that looked deceptively easy but had a weird edge case buried in it. No behavioral stuff, just pure coding the whole time.

Questions Asked (4)

Q1

Simulate placing a sequence of Tetris-like pieces (types A through E, no rotation allowed) onto an n x m grid. For each piece, find the first valid top-left anchor by scanning top-to-bottom then left-to-right, place it there, and stop if no valid placement exists. Return the final grid state.

Algorithms & Data Structures
Author's notes

The scan order part is what gets you.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the piece shapes and grid representation, then simulate the placement process by scanning each piece's possible anchor positions in row-major order. For each anchor, check if the piece fits without overlapping existing blocks or going out of bounds; if so, place it and move to the next piece, otherwise continue scanning. If no valid anchor is found for a piece, stop and return the current grid.

Pro tip: Precompute each piece's occupied cells relative to its top-left anchor to avoid repeated shape calculations, and consider using bitmasks for efficient collision checks if the grid is large.

1. Clarify requirements and assumptions

Ask about the exact shapes of pieces A-E, grid dimensions, and whether pieces can be placed on occupied cells. Confirm that scanning is top-to-bottom then left-to-right for each piece independently.

2. Represent the grid and pieces

Choose a data structure for the grid (e.g., 2D array or bitmask) and define each piece as a list of relative coordinates from its top-left anchor.

3. Simulate placement for each piece

For each piece in sequence, iterate over all possible anchor positions in row-major order. For each anchor, check if the piece fits (no out-of-bounds and no overlap). Place at the first valid anchor and break; if none, stop the simulation.

4. Return the final grid

After processing all pieces or stopping early, return the grid state, ensuring it reflects all placed pieces.

Key Points to Mention

  • Time complexity: O(P * n * m * K) where P is number of pieces, K is cells per piece; can optimize with bitmasks.
  • Space complexity: O(n*m) for the grid, plus O(K) per piece for shape representation.
  • Edge cases: piece larger than grid, no valid placement for first piece, grid completely filled.
  • Scanning order: top-to-bottom then left-to-right means row-major order (i from 0 to n-1, j from 0 to m-1).
  • Collision detection: check each cell of the piece against grid boundaries and existing blocks.
  • Early termination: stop immediately when a piece cannot be placed, without processing remaining pieces.

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

Q2

Given a sequence of house-building operations on an integer number line (coordinates can be in the billions), after each build output the length of the longest contiguous segment of built positions.

Algorithms & Data Structures
Author's notes

Classic union-find or interval merge problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash map to track the lengths of contiguous built segments, updating the lengths of the segments adjacent to each new build. After each build, maintain the maximum segment length seen so far, which only increases, so you can output it in O(1) time.

Pro tip: Emphasize that coordinates can be in the billions, so an array-based approach is infeasible; a hash map keyed by coordinate is necessary. Also, note that the maximum segment length is monotonic, so you can avoid scanning all segments each time.

1. Clarify the problem

Confirm that builds are given one by one, and after each build we need to output the current longest contiguous segment of built positions. Ask if positions can be built multiple times (assume no).

2. Choose data structures

Use a hash map (dictionary) to store the length of the contiguous segment for each endpoint of that segment. Also keep a variable for the global maximum segment length.

3. Process each build

For a new position x, check if x-1 and x+1 are already built. Compute the new segment length by combining left and right segments (if any) plus 1. Update the length for the new segment's endpoints in the hash map.

4. Update and output maximum

After each build, update the global maximum if the new segment length is larger. Output the global maximum, which is the length of the longest contiguous segment so far.

5. Analyze complexity

Each build is processed in O(1) average time due to hash map operations. Overall O(n) time and O(n) space, where n is the number of builds.

Key Points to Mention

  • Hash map to store segment lengths at endpoints, enabling O(1) lookups and updates.
  • Combining left and right segments when a new position bridges them.
  • Maintaining a global maximum that only increases, so no need to recompute from scratch.
  • Handling edge cases: first build, builds at the ends of existing segments, isolated builds.
  • Time and space complexity: O(n) time and O(n) space.
  • Coordinates can be large, so hash map is essential; array would be too sparse.

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

Q3

Starting from a rating of 1500, apply a sequence of rating changes. Return both the maximum rating ever reached and the final rating.

Algorithms & Data Structures
Author's notes

Easiest one by far.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem by confirming that the rating changes are applied sequentially and that the maximum rating includes the initial rating. Then, simulate the process in a single pass, tracking the current rating and the maximum seen so far, and return both values.

Pro tip: Mention that you can solve this in O(n) time and O(1) space, and that you would handle edge cases like an empty list of changes or all negative changes. Also, explicitly state that the maximum rating is updated after each change, including the initial rating.

1. Clarify the problem

Confirm that the rating changes are applied in order, that the initial rating is 1500, and that the maximum rating includes the starting rating. Ask if the changes can be positive, negative, or zero.

2. Define variables

Initialize current_rating = 1500 and max_rating = 1500. These will track the rating after each change and the highest rating seen so far.

3. Iterate through changes

For each change in the sequence, update current_rating by adding the change. Then, if current_rating > max_rating, update max_rating to current_rating.

4. Return results

After processing all changes, return max_rating and current_rating as the final rating.

5. Analyze complexity

State that the time complexity is O(n) where n is the number of changes, and space complexity is O(1) since only two variables are used.

Key Points to Mention

  • Single-pass simulation with O(n) time and O(1) space
  • Initializing max_rating to 1500 to include the starting rating
  • Updating max_rating after each change, not just at the end
  • Handling edge cases: empty list, all negative changes, all positive changes
  • Clarifying that the sequence is applied in order
  • Returning both values as a tuple or object

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

Q4

Given an array of non-negative integers, repeatedly find the leftmost nonzero element x, subtract x from consecutive elements to its right as long as each element is >= x, add x to a result accumulator, and repeat until the array is all zeros. Return the accumulated result.

Algorithms & Data Structures
Author's notes

The stopping condition tripped me up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem with examples to ensure you understand the operation. Then, discuss a brute-force simulation and its inefficiencies, and propose an optimized approach using a stack or monotonic stack to compute the result in O(n) time. Finally, analyze time and space complexity and test with edge cases.

Pro tip: Mention that this problem is equivalent to computing the sum over each element of the minimum of the maximums of the left and right segments, which can be solved with a monotonic stack. This shows deep insight and can lead to a clean O(n) solution.

1. Understand the problem

Restate the problem in your own words and walk through a small example to confirm the operation. Ask clarifying questions if needed.

2. Discuss brute-force

Explain a straightforward simulation that repeatedly scans for the leftmost nonzero and performs subtractions. Analyze its time complexity (likely O(n^2)) and why it's inefficient.

3. Derive optimized approach

Observe that the process is equivalent to summing, for each element, the minimum of the maximums of the left and right segments. Use a monotonic stack to compute these values efficiently.

4. Implement and test

Write clean code for the optimized solution, then test with edge cases like all zeros, single element, and increasing/decreasing arrays.

5. Analyze complexity

State the time and space complexity of the optimized solution (O(n) time, O(n) space) and compare with brute-force.

Key Points to Mention

  • Clarify the operation with examples and edge cases.
  • Brute-force simulation and its O(n^2) time complexity.
  • Optimized O(n) approach using monotonic stack.
  • Equivalence to sum of min of max of left and right segments.
  • Time and space complexity analysis.
  • Handling edge cases like all zeros or single element.

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