Compute waits and find distance-k node pairs
Company: TikTok
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency in algorithm design and data structure usage for both array and tree problems and falls under the Coding & Algorithms domain; it is commonly asked to assess algorithmic thinking, time and space complexity reasoning, and robustness in handling edge cases.
Next Higher Waits
Constraints
- Inputs are provided as Python literals matching the function signature.
- Return a deterministic exact-match result.
Examples
Input: ([73,74,75,71,69,72,76,73],)
Expected Output: [1, 1, 4, 2, 1, 1, 0, 0]
Explanation: Daily-temperatures style.
Input: ([3,2,1],)
Expected Output: [0, 0, 0]
Explanation: No higher future value.
Input: ([],)
Expected Output: []
Explanation: Empty input.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.
Binary Tree Node Pairs at Distance K
Constraints
- Inputs are provided as Python literals matching the function signature.
- Return a deterministic exact-match result.
Examples
Input: ([1,2,3,4,5,6,7], 2)
Expected Output: [[1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [4, 5], [6, 7]]
Explanation: Pairs two edges apart.
Input: ([1,2,3], 1)
Expected Output: [[1, 2], [1, 3]]
Explanation: Adjacent pairs.
Input: ([], 1)
Expected Output: []
Explanation: Empty tree.
Input: ([1], 0)
Expected Output: []
Explanation: No pair with same node.
Hints
- Choose a representation that makes the core operation simple.
- Handle empty and boundary inputs before the main algorithm.