Problems > Most Frequent in a Slice > Editorial

Most Frequent in a Slice — Solution & Editorial

Back to the Problem

Range mode has no easy prefix structure; the intended solution is Mo's algorithm (sort queries by √-blocks, maintain a frequency map and a bucketed max). At the provided sizes, counting each queried slice is acceptable.

Complexity: O((N + Q)√N) with Mo's algorithm