The sorted-characters guarantee is what makes this tractable.
Use binary search over the run-length encoded blocks to locate the first block whose character exceeds the target, then check if its start index falls within [left, right]. Handle edge cases by first finding the block containing left and adjusting the search range accordingly.
Pro tip: Clarify whether the target is guaranteed to be present and whether left/right are inclusive; also discuss the trade-off between O(log n) binary search and O(n) linear scan for small ranges.
Confirm that the decoded string is sorted, indices are inclusive, and the function should return the first index > target within [left, right]. Discuss edge cases like empty range or target larger than all characters.
Compute prefix sums of counts to map each block to its starting index in the decoded string. This allows O(1) conversion between block index and decoded index.
Use binary search on the block characters to find the smallest block index where the character is strictly greater than target. If no such block exists, return -1.
If the found block's start index is less than left, find the block containing left and check if its character > target. If so, return left; otherwise, continue from the next block.
Ensure the candidate index is ≤ right. If it is, return it; otherwise, return -1. Also handle the case where the target is greater than or equal to all characters in the range.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.