PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Solve frequency and tree-completeness problems

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem A: Return the *k* most frequent values You are given an integer array `nums` and an integer `k`. **Task:** Return the `k` distinct values that occur most frequently in `nums`. **Input** - `nums`: list of integers (length `n`) - `k`: integer, `1 <= k <= (# of distinct values in nums)` **Output** - A list of `k` integers: the values with highest frequency. **Notes / Constraints** - If multiple answers are possible due to ties, any valid order is acceptable. - Aim for better than `O(n log n)` if possible. --- ## Problem B: Check whether a binary tree is complete You are given the `root` of a binary tree. A binary tree is **complete** if: 1. Every level except possibly the last is completely filled, and 2. All nodes in the last level are as far left as possible. **Task:** Return `true` if the tree is complete; otherwise return `false`. **Input** - `root`: root node of a binary tree (each node has `val`, `left`, `right`) **Output** - Boolean: whether the tree is complete. **Constraints** - Up to ~`10^5` nodes.

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

Return k distinct values with highest frequency, tie-breaking by value ascending for determinism.

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

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.

Check Complete Binary Tree

Given level-order values with None holes, return whether the binary tree is complete.

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

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)