Facebook onsite interview. How to solve optimally?
Anonymous User
3057

Given an array of integers arr and a positive integer m, your task is to find the frequency of the most common element within each contiguous subarray of length m in arr.
Return an array of these highest frequencies among subarray elements, ordered by their corresponding subarray's starting index.

Input: [1,2,3,1,2,4,1,4,4], m = 4
Output: [2,2,1,2,2,3]

Input:[1,2], m = 2
Output:[1]

Comments (17)