Precompute the 26 cumulative counts using prefix sums. Thenand the answer is zero if . Counting and prefix summation take preprocessing time and constant storage for this fixed alphabet. Each query uses two indexed reads and one subtraction, hence time. The guard for prevents a negative answer for an empty interval.
Articles by others on the same topic
There are currently no matching articles.