A records office assigns every case a full dossier name written in lowercase letters. Clerks are allowed to write a shorthand tag for a dossier by replacing any one or more consecutive runs of letters with that run's length written as a decimal number (for example, the middle 18 letters of a 20-letter name could be replaced with the digits "18"); letters that are not replaced must appear in the tag exactly as they do in the full name, in order, and a replaced run's digit count must never be written with a leading zero. Given a full dossier name and a proposed shorthand tag, determine whether the tag is a valid abbreviation of the name.
Line 1: the full dossier name, a non-empty string of lowercase English letters.
Line 2: the proposed shorthand tag, a non-empty string made of lowercase English letters and digits 0-9.
Print true if the tag is a valid abbreviation of the name, or false otherwise.
a-z).0-9).Example 1
Input
internationalization i18n
Expected
true
Explanation
The dossier name has 20 letters. The tag starts by matching the letter 'i' against the name's first character (match), then the digit run "18" skips the next 18 characters of the name, landing exactly on the 20th character, which must be 'n' -- and it is. Since the whole tag was consumed and the position lands exactly at the end of the 20-letter name, the abbreviation is valid, so the answer is true.
Example 2
Input
apple a2e
Expected
false
Explanation
The tag's 'a' matches the name's first letter. The digit run "2" then skips 2 characters, moving from position 1 to position 3 in "apple" (a-p-p-l-e), landing on 'l'. The tag's next character is 'e', but the name has 'l' at that position, so the letters do not match and the answer 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 →