Solve the following data-structures problems:
(
-
Given two sorted integer lists A and B, merge them into a single non-decreasing array. Then, for a target x, return the indices of the first element ≥ x (lower bound) and the first element > x (upper bound) in the merged array. Specify time and space complexity, and handle duplicates and empty inputs.
(
-
Implement a function that returns the minimum value in an array; discuss approaches and edge cases for both sorted and unsorted arrays.
(
-
Given a 2D grid of 0s (open) and 1s (walls) and a start cell, find a path to any exit on the grid boundary (an open boundary cell) and return the path as a list of coordinates. Discuss BFS vs. DFS, how to reconstruct the path, and complexity.
(
-
Design a class MovingAverage(k) that ingests a stream of numbers and returns the average of the last k values after each insertion. Support amortized O(
-
updates/queries and define behavior when the stream has fewer than k elements.