Skip to content
StackDecode
Advanced data structuresExplained

Mo's Algorithm

Answer offline range queries by sorting them to minimise pointer movement.

Time

O((n + q) √n)

Extra space

O(n)

Use it for

Offline range queries.

An animated walkthrough for this algorithm isn’t built yet. The summary above explains the idea; see the related animated algorithms below to practise the same technique.