One Shot at Life
Time limit1sMemory limit1024 MB
Decide whether a string of uppercase letters has a run of 5 or more characters where each adjacent pair is alphabetically consecutive.
- Level
Easy2 of 10
- Topics
- String, Simulation
- Solved
- No attempts yet
Problem
Jaehyung bought a lotto ticket today too, hoping to turn his life around. Each ticket is a string of uppercase letters written in a row. To win, the string must contain a substring of length or more in which every pair of adjacent characters is adjacent in alphabetical order. For example, the alphabetical neighbors of 'C' are 'B' and 'D', the only neighbor of 'Z' is 'Y', and no letter is its own neighbor. So the tickets "ABCDE", "ASGXYZYXE", and "WEFGHIJKA" win, while "ABCDF", "CXYZAB", and "AAAAA" do not. Given a string of uppercase letters, determine whether the ticket wins.
Input
The first line contains (), the length of the lotto string. The second line contains the lotto string .
Output
If the ticket wins, print YES. Otherwise, print NO.
Hint
A substring of is a contiguous part of the string.