Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use sliding window.
Use two sets ordered by frequency. One of the sets will only contain the top <code>x</code> frequent elements, and the second will contain all other elements.
Update the two sets whenever you slide the window, and maintain a sum of the elements in the set with <code>x</code> elements