Solve array merge and tree flattening problems
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: HR Screen
1) Given two sorted arrays, merge them into a single sorted array. Provide both an in-place approach (when the first array has enough trailing capacity) and an approach using extra buffer. Analyze time and space complexity for each, and discuss stability.
2) Given a binary tree, flatten it in-place to a singly linked list following preorder traversal such that each node's right pointer points to the next node and all left pointers are null. Describe the algorithm, prove correctness, and analyze time and space complexity.
Quick Answer: This question evaluates a candidate's ability to design and analyze algorithms on arrays and tree-based linked structures, focusing on merging sorted arrays (comparing in-place and extra-buffer approaches, stability, and complexity) and flattening a binary tree into a preorder-linked list with in-place pointer manipulation.