← Meta Interview Insights

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

Intermediate
Jun 2026

Summary

Meta software engineer interview covering a mix of stack-based simulation, interval scheduling, tree traversal, and selection algorithms. Pretty standard Meta coding lineup if you've seen their question pool before.

Questions Asked (4)

Q1

Given a list of function call logs with start and end timestamps, calculate the exclusive execution time for each function.

Algorithms & Data Structures
Author's notes

Stack problem but the off-by-one stuff in the time calculation tripped me up.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the logs as a call tree or use a stack to track active functions, then compute exclusive time by subtracting time spent in child calls from each function's total elapsed time. Alternatively, use a timestamp sweep with a stack to accumulate exclusive time in a single pass.

Pro tip: Clarify assumptions upfront: whether logs are well-formed (proper nesting, no overlapping calls) and if timestamps are inclusive/exclusive. This shows attention to detail and avoids edge-case bugs.

1. Clarify input format and assumptions

Ask about log structure (e.g., function ID, start/end times), nesting rules, and whether timestamps are integers or floats. Confirm if logs are sorted and if calls can overlap or be malformed.

2. Choose a data structure

Decide between building a call tree or using a stack for a single-pass solution. A stack is often simpler and more efficient for streaming logs.

3. Compute exclusive time

For each function, calculate total elapsed time (end - start) and subtract the exclusive times of all direct child calls. With a stack, maintain a running total and adjust when entering/leaving functions.

4. Handle edge cases

Consider recursive calls, multiple calls to the same function, zero-duration calls, and timestamps that are inclusive on both ends. Ensure the algorithm correctly aggregates exclusive time per function.

5. Analyze complexity and test

State time and space complexity (typically O(n) time, O(d) space where d is max depth). Walk through a small example to verify correctness.

Key Points to Mention

  • Use a stack to track the current call stack and compute exclusive time in one pass.
  • Exclusive time = total elapsed time - sum of exclusive times of direct children.
  • Handle recursive calls and multiple invocations of the same function by aggregating results.
  • Clarify whether timestamps are inclusive/exclusive and if logs are sorted.
  • Time complexity O(n) and space complexity O(d) for depth of call stack.
  • Consider edge cases like zero-duration calls and malformed logs.

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

Q2

Given an array of meeting intervals, find the minimum number of conference rooms required to hold all meetings.

Algorithms & Data Structures
Author's notes

Classic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and edge cases, then propose a sweep-line algorithm: separate start and end times, sort both, and use two pointers to count concurrent meetings. Alternatively, use a min-heap to track end times while iterating through meetings sorted by start time. Analyze time and space complexity, and discuss trade-offs.

Pro tip: Mention that the sweep-line approach is optimal for large inputs and can be extended to find the exact time of peak usage. Also, proactively discuss how to handle edge cases like empty input or back-to-back meetings.

1. Clarify requirements and edge cases

Ask if intervals are inclusive/exclusive, if input is sorted, and what to return for no meetings. Confirm that overlapping meetings require separate rooms.

2. Outline a brute-force approach

Briefly mention that a naive O(n^2) approach checking overlaps for each meeting is possible but inefficient, setting the stage for optimization.

3. Propose an optimal algorithm

Describe the sweep-line method: extract start and end times, sort them, and use two pointers to count active meetings, updating max rooms. Alternatively, explain the min-heap approach.

4. Analyze complexity and trade-offs

State that both approaches run in O(n log n) time due to sorting, with O(n) space. Compare with brute-force and mention when each might be preferable.

5. Test with examples and edge cases

Walk through a sample input like [[0,30],[5,10],[15,20]] to show the algorithm yields 2 rooms. Discuss edge cases like empty input or all meetings overlapping.

Key Points to Mention

  • Sorting start and end times separately
  • Two-pointer technique to count concurrent meetings
  • Min-heap to track end times of ongoing meetings
  • Time complexity O(n log n) and space complexity O(n)
  • Handling edge cases: empty input, back-to-back meetings, large inputs
  • Potential follow-up: find the time of peak usage or assign specific rooms

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

Q3

Given a binary tree, return its nodes grouped by vertical column order from left to right.

Algorithms & Data Structures
Author's notes

BFS with a column tracker.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a BFS traversal while tracking each node's horizontal distance (column index) from the root, storing nodes in a map keyed by column. Then output the columns in sorted order from leftmost to rightmost, preserving top-to-bottom order within each column.

Pro tip: Clarify whether nodes in the same column and row should be ordered by their left-to-right position; if so, augment BFS with a row index and sort within each column by row, then by value or insertion order.

1. Clarify requirements and edge cases

Ask about ordering within a column (top-to-bottom, and tie-breaking for same row), and confirm handling of empty tree or single node.

2. Choose traversal and data structures

Use BFS with a queue storing (node, column, row) and a hash map from column to list of nodes; alternatively DFS with column tracking.

3. Traverse and populate columns

Process nodes level by level, updating column indices (left child: col-1, right child: col+1) and appending nodes to the corresponding column list.

4. Sort columns and format output

Extract column keys, sort them ascending, and for each column, ensure nodes are ordered top-to-bottom (and left-to-right if same row) before adding to result.

5. Analyze complexity and test

State time and space complexity (O(n log n) due to sorting, or O(n) with ordered map), and walk through a small example to verify correctness.

Key Points to Mention

  • BFS is natural for top-to-bottom ordering within columns; DFS can also work with careful ordering.
  • Use a hash map (or TreeMap) to group nodes by column index.
  • Track horizontal distance: root at 0, left child -1, right child +1.
  • Sort columns from leftmost (smallest index) to rightmost (largest index).
  • Within a column, nodes should appear top-to-bottom; if same row, left-to-right.
  • Time complexity: O(n log n) with sorting, or O(n) if using an ordered map; space O(n).

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

Q4

Find the Kth largest element in an unsorted array.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

They asked for better than sort.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., array size, value range, duplicates) and then present multiple solutions with trade-offs. Begin with a simple sorting approach, then optimize using a min-heap of size k or Quickselect for average O(n) time. Discuss the choice based on expected input and system constraints.

Pro tip: Mention that Quickselect has O(n) average but O(n^2) worst-case, and you can avoid the worst-case by using a randomized pivot or the Median of Medians algorithm. Also, note that for streaming data or when k is small, a heap is more practical.

1. Clarify requirements and constraints

Ask about input size, value range, whether duplicates count as separate elements, and if the array can be modified. This shows you consider edge cases and practical limits.

2. Propose a baseline solution

Suggest sorting the array and returning the element at index n-k. This is simple and O(n log n) time, O(1) extra space if in-place, but may be inefficient for large n.

3. Optimize with a heap

Explain using a min-heap of size k: iterate through the array, push elements, and if heap size exceeds k, pop the smallest. At the end, the heap root is the kth largest. This is O(n log k) time and O(k) space, good for large n and small k.

4. Present Quickselect for average O(n)

Describe the Quickselect algorithm: partition the array around a pivot, then recursively search the side that contains the kth largest. Average O(n) time, worst-case O(n^2), but can be mitigated with random pivots.

5. Compare trade-offs and choose

Discuss when to use each approach: sorting for simplicity, heap for streaming or small k, Quickselect for optimal average time when the array can be modified. Mention that Quickselect modifies the array, which may not be allowed.

Key Points to Mention

  • Time and space complexity of each approach (sorting: O(n log n), heap: O(n log k), Quickselect: O(n) average, O(n^2) worst-case).
  • Handling duplicates: clarify if kth largest means kth distinct element or kth in sorted order including duplicates.
  • Edge cases: k=1 (maximum), k=n (minimum), empty array, k out of bounds.
  • Stability and whether the original array can be modified (Quickselect modifies it).
  • Randomized pivot selection to avoid worst-case in Quickselect.
  • Alternative: using a max-heap of size n and extracting k times, but that's O(n + k log n) which is worse than min-heap for small k.

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