PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in array frequency analysis and binary tree traversal, testing skills in data structures, correctness reasoning, and algorithm implementation.

  • easy
  • Meta
  • Coding & Algorithms
  • Software Engineer

Implement array parity and tree level views

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Implement the following coding tasks. 1. **Check whether all values occur an even number of times** - Input: an integer array `nums`. - Output: return `true` if every distinct value appears an even number of times, otherwise return `false`. - Example: `[1, 2, 1, 2, 3, 3] -> true`, `[4, 5, 4, 5, 4] -> false`. 2. **Compute several breadth-first traversal results for a binary tree** - Input: the root of a binary tree. - Implement functions to return: - the nodes visible when the tree is viewed from the right side, - the nodes visible when the tree is viewed from the left side, - the average value of nodes at each depth level. - Example: - For a tree with level order `[3, 9, 20, null, null, 15, 7]`, - right view -> `[3, 20, 7]` - left view -> `[3, 9, 15]` - level averages -> `[3.0, 14.5, 11.0]` A breadth-first traversal approach is acceptable for the tree problems.

Quick Answer: This question evaluates proficiency in array frequency analysis and binary tree traversal, testing skills in data structures, correctness reasoning, and algorithm implementation.

Part 1: Check Whether All Array Elements Appear an Even Number of Times

Given an integer array nums, determine whether every distinct value appears an even number of times. Return True if all values have even frequency, otherwise return False.

Constraints

  • 0 <= len(nums) <= 100000
  • -10^9 <= nums[i] <= 10^9

Examples

Input: []

Expected Output: True

Explanation: The array is empty, so there are no values with odd frequency.

Input: [2, 2, 3, 3, 4, 4]

Expected Output: True

Explanation: Each distinct number appears exactly twice.

Input: [1, 2, 2, 1, 3]

Expected Output: False

Explanation: 1 appears twice and 2 appears twice, but 3 appears once, which is odd.

Input: [-1, -1, -2, -2, -2, -2]

Expected Output: True

Explanation: -1 appears twice and -2 appears four times; both are even counts.

Input: [7]

Expected Output: False

Explanation: 7 appears once, which is an odd frequency.

Hints

  1. Try tracking which numbers currently have odd frequency as you scan the array.
  2. If a number is seen once, it becomes odd; if seen again, it becomes even.

Part 2: Right Side View of a Binary Tree

You are given a binary tree in level-order list form, where None represents a missing child. Return the values visible when looking at the tree from the right side, from top to bottom.

Constraints

  • 0 <= len(tree) <= 10000
  • -1000 <= node values <= 1000
  • The input list follows standard level-order tree encoding with None for missing children

Examples

Input: ([1, 2, 3, None, 5, None, 4],)

Expected Output: [1, 3, 4]

Explanation: At each level, the rightmost visible nodes are 1, then 3, then 4.

Input: ([1, 2, None, 3],)

Expected Output: [1, 2, 3]

Explanation: The tree extends down the left side, so the visible nodes from the right are still one node per level: 1, 2, and 3.

Input: ([],)

Expected Output: []

Explanation: An empty tree has no visible nodes.

Input: ([7],)

Expected Output: [7]

Explanation: A single-node tree is visible as just that node.

Input: ([None],)

Expected Output: []

Explanation: A list starting with None represents an empty tree.

Input: ([-1, -2, -3, None, -5],)

Expected Output: [-1, -3, -5]

Explanation: The rightmost nodes by level are -1 at the root, -3 on the second level, and -5 on the third level.

Hints

  1. Process the tree one level at a time using a queue.
  2. At each level, the last node you visit is the one visible from the right.

Part 3: Left Side View of a Binary Tree

You are given a binary tree in level-order list form, where None represents a missing child. Return the values visible when looking at the tree from the left side, from top to bottom.

Constraints

  • 0 <= len(tree) <= 10000
  • -1000 <= node values <= 1000
  • The input list follows standard level-order tree encoding with None for missing children

Examples

Input: ([1, 2, 3, None, 5, None, 4],)

Expected Output: [1, 2, 5]

Explanation: At each depth, the leftmost visible nodes are 1, then 2, then 5.

Input: ([1, 2, None, 3],)

Expected Output: [1, 2, 3]

Explanation: The tree goes down the left side as 1 -> 2 -> 3, so all three are visible.

Input: ([],)

Expected Output: []

Explanation: An empty tree has no visible nodes.

Input: ([7],)

Expected Output: [7]

Explanation: A tree with only a root shows just that root.

Input: ([0, -1, -1, None, -2],)

Expected Output: [0, -1, -2]

Explanation: The visible nodes from the left are the root 0, then the left child -1, then its right child -2.

Hints

  1. Use breadth-first search to process one level at a time.
  2. At each level, the first node you remove from the queue is the one visible from the left.

Part 4: Average Value of Each Level in a Binary Tree

You are given a binary tree in level-order list form, where None represents a missing child. Compute the average node value at each depth and return the list of averages from top to bottom.

Constraints

  • 0 <= len(tree) <= 10000
  • -100000 <= node values <= 100000
  • The input list follows standard level-order tree encoding with None for missing children

Examples

Input: ([3, 9, 20, None, None, 15, 7],)

Expected Output: [3.0, 14.5, 11.0]

Explanation: Level 0 has [3], level 1 has [9, 20], and level 2 has [15, 7]. Their averages are 3.0, 14.5, and 11.0.

Input: ([5],)

Expected Output: [5.0]

Explanation: A single-node tree has one level, so the average is just the root value.

Input: ([],)

Expected Output: []

Explanation: An empty tree has no levels.

Input: ([1, None, 2, 3],)

Expected Output: [1.0, 2.0, 3.0]

Explanation: This compact level-order form means 2 is the right child of 1, and 3 is the left child of 2.

Input: ([-4, -2, -6, None, 0, 8],)

Expected Output: [-4.0, -4.0, 4.0]

Explanation: The levels are [-4], [-2, -6], and [0, 8], giving averages -4.0, -4.0, and 4.0.

Hints

  1. Breadth-first search naturally groups nodes by level.
  2. For each level, keep a running sum and divide by the number of nodes in that level.
Last updated: Apr 19, 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
  • 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)