← Geico Interview Insights

Geico·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Had a technical phone screen for a Software Engineer role at Geico. One coding problem, tree-related, and it was trickier than it looked on the surface.

Questions Asked (1)

Q1

Given the root of a binary tree, return its boundary nodes in anti-clockwise order starting from the root. The boundary includes the root, the left boundary (top to bottom, no leaves), all leaf nodes (left to right), and the right boundary (bottom to top, no leaves), with no duplicates.

Algorithms & Data Structures
Author's notes

I thought I had it after reading the problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into three distinct traversals: left boundary (excluding leaves), all leaves (left-to-right), and right boundary (excluding leaves, collected bottom-up). Use DFS to collect nodes, ensuring no duplicates by carefully defining which nodes belong to each part. Then concatenate the results in the correct order.

Pro tip: Clarify with the interviewer whether the root should be included if it's also a leaf (i.e., tree with only root). Also, explicitly state that you'll avoid duplicates by not adding leaves during boundary traversals.

1. Handle edge cases and define boundaries

Check if the root is null; if so, return an empty list. Also, if the tree has only one node, return that node as the boundary. Define left boundary as nodes from root's left child down to the leftmost node, excluding leaves.

2. Collect left boundary nodes

Traverse from the root's left child, preferring left child over right, and add nodes to the result if they are not leaves. Stop when you reach a leaf.

3. Collect all leaf nodes

Perform a DFS (preorder) traversal of the entire tree, adding nodes that have no children (leaves) to the result in left-to-right order.

4. Collect right boundary nodes

Traverse from the root's right child, preferring right child over left, and add nodes to a temporary list if they are not leaves. After traversal, reverse the list and append to the result.

5. Combine and return

Concatenate the root value (if not already included), left boundary, leaves, and reversed right boundary. Ensure no duplicates by not adding leaves in boundary traversals.

Key Points to Mention

  • Definition of boundary: root, left boundary (excluding leaves), leaves (left-to-right), right boundary (excluding leaves, bottom-up).
  • Handling edge cases: empty tree, single node, skewed trees.
  • Avoiding duplicates by excluding leaves from left and right boundary traversals.
  • Time complexity O(n) and space complexity O(n) due to recursion stack and output list.
  • Implementation details: recursive DFS for left and right boundaries, and for leaf collection.
  • Order of concatenation: root, left boundary, leaves, reversed right boundary.

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