Solve four data structure and algorithms tasks
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
1) Print the numbers at each level of a binary tree. Given the root, output the values level-by-level (each level on a new line or as a list of lists). State the time and space complexity.
2) Implement a class that stores input strings and their occurrence counts with methods: add(s), count(s) -> current count, and remove(s). Follow-ups: compute the total count across all stored data efficiently; generalize to support arbitrary data types (not just strings) and interchangeable underlying data structures; discuss concurrency and complexity trade-offs.
3) Given a binary tree with integer values, determine for each node whether its value equals the average of all values in its subtree (including itself). Return the number of nodes that satisfy the condition. Design an O(n) solution.
4) Given an array of wood lengths and an integer k, find the maximum integer length L such that cutting the wood into pieces of length L yields at least k pieces (no joining allowed). If impossible, return 0. Explain and implement your algorithm.
Quick Answer: This set of tasks evaluates core algorithmic competencies such as tree traversal and level-order processing, data-structure design and counting maps, recursive subtree aggregation for statistical checks, and optimization/search techniques for partitioning problems, all within the Coding & Algorithms domain.