All Tracks Algorithms String Algorithms String Searching Problem

Playful Strings
Tag(s):

Easy, Implementation

Problem
Editorial
Analytics

Given a string $$S$$ of length $$N$$, you have to tell whether it is playful or not. A playful string is one where the distance between any two adjacent character is exactly $$1$$. Consider that the alphabets are arranged in cyclic manner from '$$a$$' to '$$z$$'. Hence, distance between any character '$$i$$' and '$$j$$' will be defined as minimum number of steps it takes '$$i$$' to reach '$$j$$'. Here, character '$$i$$' can start moving clockwise or anti-clockwise in order to reach at position where character '$$j$$' is placed. Your task is simple, where you just need to print "YES" or "NO"(without quotes) depending on whether the given string is playful or not.

Input
First line of the input contains $$T$$ denoting the number of test cases.
$$T$$ lines follow, each having a string $$S$$.

Output
Print the answer for each testcase in a separate line.

Constraints

  • $$1 ≤ T ≤ 50$$
  • $$1 ≤ |S| ≤ 50$$
  • $$S$$ contains only lowercase alphabetic characters

SAMPLE INPUT
3
aba
zza
bcd
SAMPLE OUTPUT
YES
NO
YES

Explanation

Sample Case 1: 'aba' is a playful string, since all the adjacent characters are exactly 1 unit of distance apart. Sample Case 2: 'zza' is not a playful string since 'z' and 'z' are at the same position and hence 0 distance apart.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

HackerEarth Collegiate Cup - Qualifier

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications