We have a long string. We label some substrings with tags.
- A tag entry is [startIndex, endIndex, tag].
- Query: 1 or more tags
- Output: all blocks/ranges with all queried tags.
Example tag entries: [23, 72, 0]
// label [23, 72) with tag 0 [34, 53, 1]
// label [34, 53) with tag 1 [100, 128, 0]
Query and Output: 0 => [23, 72], [100, 128] 0,1 => [34,53]
// [34, 53) matches both tag 0 and 1
Give an efficient algorithm. Please describe your algorithm before posting code.