← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Meta SWE coding round, one question on BSTs. Pretty focused session, nothing too wild, but the problem had a wrinkle that took me a minute to fully see.

Questions Asked (1)

Q1

Given a Binary Search Tree, find the length of the longest path (measured in number of nodes) where the node values form a strictly increasing sequence. The path only follows parent-child edges and doesn't need to pass through the root.

Algorithms & Data Structures
Author's notes

My first instinct was to just do a DFS and track the current run length, resetting whenever the sequence broke.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a post-order DFS that returns the longest strictly increasing path starting at each node, combining results from left and right children. For each node, compute the best increasing path that starts at that node by considering valid child paths where the child's value is greater, then update a global maximum with the sum of the two best child paths plus one (the node itself).

Pro tip: Clarify that the path must be strictly increasing and can go through a node by combining its left and right child paths, but only if both child values are greater than the node's value. Also, mention that the path doesn't need to be root-to-leaf, so you must track the global maximum at every node.

1. Clarify the problem and edge cases

Confirm that the path follows parent-child edges, values must be strictly increasing, and the path length is measured in nodes. Discuss edge cases like empty tree, single node, and trees with duplicate values (though BSTs typically have unique values).

2. Define the recursive function

Design a DFS function that returns the length of the longest strictly increasing path starting at the current node and going downwards. This function will be called recursively on left and right children.

3. Compute local and global maxima

At each node, compute the best increasing path starting at the node by considering valid child paths (where child value > node value). Update a global maximum with the sum of the two best child paths plus one (the node itself) to account for paths that pass through the node.

4. Handle base cases and return values

For null nodes, return 0. For leaf nodes, return 1. Ensure the function returns the longest increasing path starting at the current node (1 + max of valid child paths).

5. Analyze complexity and test

State that the time complexity is O(n) since each node is visited once, and space complexity is O(h) for recursion stack. Walk through a small example to verify correctness.

Key Points to Mention

  • Post-order DFS traversal to process children before parent
  • Strictly increasing condition: only consider child paths where child value > current node value
  • Global maximum tracking to capture paths that don't start at the root
  • Combining left and right child paths at a node to form a longer path through the node
  • Time and space complexity analysis: O(n) time, O(h) space
  • Edge cases: empty tree, single node, skewed tree

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