Data Structures & AlgorithmsVery hardCodeforces Div2 E · offline queries

Problem: Mo's algorithm answers q range queries on an array of length n by sorting queries into blocks of size about sqrt(n) and moving the window pointers. What is its total running time?

  1. A. O((n + q) * sqrt(n))
  2. B. O(n + q)
  3. C. O(n * sqrt(q) * log n)
  4. D. O((n + q) * log n)

Correct answer: A. O((n + q) * sqrt(n))

Within each block the right pointer moves monotonically, giving O(n sqrt n) per block sweep and O(q sqrt n) pointer moves over all queries. The total is O((n + q) sqrt n).

More Coding Interview Problems questions

Exams that ask this topic