Company: Vmock

Difficulty: medium

Problem Statement

Array Challenge Write the function ArrayChallenge(arr) so that it reads the numbers stored in arr , where the very first entry is a sliding window size N and every entry after that is a data point. For each data point, compute the median of that point together with its N-1 predecessors (a shrinking window near the start, growing to full size N once enough points have arrived). Join the resulting medians, one per data point, into a single comma-separated string and return that string. Near the beginning of the array, before the window has grown to N entries, take the median over however many points are currently available. For instance, if arr is [3, 1, 3, 5, 10, 6, 4, 3, 1], the function should return "1,2,3,5,6,6,4,3" Input Format An array arr whose first entry is the window size N, followed by the sequence of data points. Output Format A comma-separated string of the computed moving medians. Constraints The sliding window size N will always be less than or equal to the length of the

More Vmock OA questionsInterview experiences