Solve frequency and tree-completeness problems
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: These two problems evaluate competency in frequency counting and selection algorithms for identifying top-k elements and in binary tree structure analysis and traversal for checking completeness, belonging to the Coding & Algorithms domain and the broader data structures and algorithms category.
Top K Frequent Values
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([1,1,1,2,2,3], 2)
Expected Output: [1, 2]
Explanation: Classic example.
Input: ([4,4,5,5], 1)
Expected Output: [4]
Explanation: Tie by value.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.
Check Complete Binary Tree
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([1,2,3,4,5,6],)
Expected Output: True
Explanation: Complete.
Input: ([1,2,3,4,None,6,7],)
Expected Output: False
Explanation: Gap before node.
Input: ([],)
Expected Output: True
Explanation: Empty tree complete.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.