15Serialize and deserialize a binary tree▼mediumMetaGleanOpenAI2 replies○ sign inA tree question that's secretly a format-design question, which is why FDE loops love it. The preorder-with-null-markers trick is clean, but the delimiter and malformed-input follow-ups are where offers are decided.Open full answer →
41Given a file-system hierarchy and timestamped permission changes, can user X access file F at time T?▼mediumElevenLabs1 replies◆ premiumThe reported ElevenLabs live round, written in a shared Google Doc, no execution, no autocomplete. Inherited folder permissions plus permission-change timestamps, and the two-axis resolution rule that keeps the code to thirty lines.Open full answer →
81Validate a binary search tree▼medium★ EssentialAmazonMetaGoogle2 replies◆ premiumAlmost everyone writes the version that only compares each node to its immediate children, and almost every interviewer has a counterexample ready. The fix is to carry a valid (low, high) range down the recursion, or to check that an inorder traversal is strictly increasing.Open full answer →
82Compute the diameter of a binary tree▼mediumMetaGoogle1 replies◆ premiumThe longest path between any two nodes need not pass through the root, which is what trips people up. The clean answer is one DFS that returns each node's height while updating a global best as it goes. First, nail down whether diameter counts edges or nodes.Open full answer →
83Maximum path sum in a binary tree▼hardMetaAmazonGoogle2 replies◆ premiumA path can start and end anywhere and bends through at most one node, values can be negative, and you want the maximum sum. The move is a DFS that returns the best downward gain (clamped at zero) while a global max tracks the best path that bridges through each node.Open full answer →
84Construct a binary tree from its preorder and inorder traversals▼mediumAmazonMicrosoftGoogle2 replies◆ premiumThe clean answer hinges on one insight: preorder names the root, inorder splits left from right. The trap is the O(n squared) version that slices arrays and scans for the root; the O(n) version uses a hashmap of inorder indices and passes bounds instead.Open full answer →