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.