#K6986. Beautiful String Checker
Beautiful String Checker
Beautiful String Checker
You are given a string s
. Your task is to check whether the string is "beautiful" or not.
A string is called beautiful if it satisfies the following two conditions:
- All characters in the string are distinct. This means for any two different indices i and j, we have
s[i] ≠ s[j]
. In mathematical notation, \(\forall i \neq j, s_i \neq s_j\). - The absolute difference between the ASCII values of every two consecutive characters is exactly 1. That is, for every index \(i\) (with \(0 \leq i < n-1\)), \(|s_{i+1} - s_i| = 1\).
Note that an empty string is considered beautiful.
inputFormat
The input consists of a single line that contains the string s
. The string can be empty or consist of lowercase/uppercase letters.
outputFormat
Output a single word: YES
if the string is beautiful according to the conditions stated, and NO
otherwise.
abcdef
YES