Consider the $[l, r]$ that is longest, then we will at least need $r-l+1$ distinct values. let this value be $m$, then we can just put the numbers $1, \cdots, m$ and keep repeating these (i.e. put the number $((i-1) \mod m) + 1$ at index $i$). Since all conditions are of length smaller or equal to $m$, this is a valid solution and the optimal solution.

Statistics

67% Solution Ratio
ASIF_GSCEarliest, Mar '21
Kuddus.6068Fastest, 0.0s
ASIF_GSCLightest, 655 kB
blizzardShortest, 213B
Toph uses cookies. By continuing you agree to our Cookie Policy.