#K55287. Beautiful String Verification
Beautiful String Verification
Beautiful String Verification
Given a string s
containing lowercase alphabetic characters and/or digits, determine whether the string is beautiful. A string is considered beautiful if, after removing all digits, the remaining letters are all distinct, and when sorted in ascending order, every pair of consecutive letters differ by exactly one in their ASCII values. In other words, if the extracted letter sequence is \( s_1, s_2, \dots, s_k \), then for each \( i \) from 1 to \( k-1 \) it must hold that \( |\mathrm{ord}(s_{i+1})-\mathrm{ord}(s_i)| = 1 \).
Note that if there is only one or no alphabetic character, the string is automatically considered beautiful. For example, abc
is beautiful because the letters satisfy \( |b-a| = 1 \) and \( |c-b| = 1 \), whereas abd
is not since \( |d-b| \) is not 1.
inputFormat
The input consists of a single line, containing a string s
(with \(1 \le |s| \le 10^5\)) composed of lowercase letters and/or digits.
outputFormat
Output YES
if the string is beautiful according to the given conditions; otherwise, output NO
.
abc
YES
</p>