2049
You are an archaeologist that comes across the Mayan Calendar. The Calendar is a continuous inscription of different characters of the Mayan Alphabet. The Mayan Language is difficult to decipher. However, all letters are directly mappable to the lowercase English alphabet and Arabic numerals from 0-9. You notice that the number ‘2049’ appears quite a few times within this inscription and are convinced it is linked to something significant. However, since the number by itself is meaningless, you want to recognize the number of substrings in the inscription which contain at least one instance of the number ‘2049’.
Note: Multiple occurences of the same substring are considered different.
Input Format
- String S denoting the inscription.
Output Format
- Integer denoting number of substrings which contain the number ‘2049’.
Constraints
-
1 \(\leq\) S \(\leq\) 5000 ( S is the string’s length ) - Each character of S is a lowercase character of the English alphabet or a Arabic numeral from 0-9.
Sample Input 0
20492p049s
Sample Output 0
7
Sample Input 1
20492049
Sample Output 1
9
Open on HackerRank ↗ · Markdown source · Back to the archive