A calibration lab records a diagnostic tape: a string of lowercase Latin letters in which every letter that appears on the tape appears exactly twice, marking the two ends of one sensor tag. A specification sheet lists, for every possible tag letter 'a' through 'z', the exact number of characters that must lie strictly between its two occurrences on the tape. Given a tape and its specification sheet, determine whether every tag letter that actually appears on the tape satisfies its required interior gap.
s of lowercase English letters, where every letter occurring in s occurs exactly twice.spec[0], spec[1], ..., spec[25], where spec[k] is the required interior gap for the letter chr(ord('a') + k).Print true if, for every letter c that occurs twice in s at 0-indexed positions i < j, j - i - 1 equals spec[ord(c) - ord('a')]; otherwise print false.
Example 1
Input
abba 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Expected
true
Explanation
'a' occurs at positions 0 and 3, giving gap 3-0-1=2, which matches spec[0]=2. 'b' occurs at positions 1 and 2, giving gap 2-1-1=0, which matches spec[1]=0. Every occurring letter satisfies its spec, so the output is true.
Example 2
Input
abba 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Expected
false
Explanation
'a' still occurs at positions 0 and 3 with actual gap 2, but spec[0] is now 1, so 'a' fails its requirement and the output is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →