Meta VO Interview Question: Sliding Window Average and Kth Smallest in Sorted Arrays

20 Views
No Comments

Given an array of integers and an integer k, for each element x in the array one can construct a slice of the array that includes x and k - 1 elements before x (k elements in total). This is called a rolling window, and k is called the window size.

Given an array of integers and a window size, write a function that returns the average value for each rolling window.

You have m arrays of sorted integers. The sum of the array lengths is n. Find the kth smallest value of all the values.

The extracted content combines two classic interview tasks: computing rolling-window averages on an integer array and finding the kth smallest value across multiple sorted arrays. The first is typically solved with a sliding window that maintains the running sum in O(n) time. The second is commonly solved with a min-heap or a divide-and-conquer strategy over the heads of the sorted arrays, often achieving O(k log m) or better depending on the approach.

END
 0