Meta·Software Engineer·Onsite - Coding / Algorithms
Apr 2026
Six coding problems back to back for a Meta SWE round, heavy on trees and graphs with some greedy/DP mixed in. The questions weren't impossible but the breadth meant you had to context-switch fast, and a couple of the follow-ups (especially the flight cost one) required more thought than I expected.
- Given the root of a binary search tree and two integers representing a range, return the sum of all node values that fall within that range. How would you use DFS with BST-specific pruning, and what are the time and space complexities?
- Given a binary tree (not necessarily a BST) and two nodes p and q that are guaranteed to exist, return their lowest common ancestor. Walk through both recursive and iterative approaches and compare their complexities.
- You have a list of departure flights and a list of return flights, each with a date and price. Find one departure and one return such that the return date is strictly after the departure date and the combined price is minimized. Design an O(n) solution if inputs are pre-sorted by date, and describe an O(n log n) approach otherwise.
- Given a binary tree, count how many nodes have a value equal to the floor of the average of all values in their subtree (including themselves). Provide an O(n) solution.
- Given a binary grid of 0s and 1s and a starting cell, return all cells 4-directionally connected to the starting cell with the same value. As a follow-up, return the border neighbors: cells adjacent to the component that are not part of it. Discuss BFS vs DFS trade-offs and analyze complexity.
- Given a binary tree, determine whether it represents a valid max-heap. This requires checking both the completeness property (levels filled left to right with no gaps) and the heap-order property (every node is greater than or equal to its children). Implement an O(n) BFS-based solution and explain why DFS alone can fail to catch completeness violations.
“Pretty standard BST problem.” The rest of the author's notes on Software Engineer interview at Meta, Onsite - Coding / Algorithms round, covers how they worked through the question, what the panel pushed back on, and what they would do differently.
View Post