Given a string s of length N, you have to tell whether it is good or not. A good string is one where the distance between every two adjacent character is exactly 1. Here distance is defined by minimum distance between two character when alphabets from 'a' to 'z' are put in cyclic manner. For example distance between 'a' to 'c' is 2 and distance between 'a' to 'y' is also 2. The task is to print "YES" or "NO" (without quotes) depending on whether the given string is Good or not.
 
Example 1:
Input: s = "aaa"
Output: NO
Explanation: distance between 'a' and 'a' is not 1.
 
Example 2:
Input: s = "cbc"
Output: YES
Explanation: distance between 'b' and 'c' is 1.
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function isGoodString() which accepts a string as input parameter and returns "YES" or "NO" (without quotes) accordingly.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
String contains only lower case english alphabets.
1 <= N <= 10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:

    def isGoodString(self, s):
        # code here


Solutions:
class Solution:

	def isGoodString(self, s):
		for i in range(len(s) - 1):
			dist = abs(ord(s[i]) - ord(s[i + 1]))
			if dist != 1 and dist != 25:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		n = len(s)
		for i in range(n - 1):
			dist = abs(ord(s[i]) - ord(s[i + 1]))
			if dist > 13:
				dist = 26 - dist
			if dist != 1:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		for i in range(1, len(s)):
			if s[i] == 'a' and s[i - 1] == 'z' or (s[i] == 'z' and s[i - 1] == 'a'):
				continue
			elif abs(ord(s[i]) - ord(s[i - 1])) != 1:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		if len(s) == 2:
			m = ord(s[0]) - ord(s[1])
			if m < 1:
				m = m * -1
			m = m % 24
			if m == 1:
				return 'YES'
			else:
				return 'NO'
		i = 1
		while i < len(s) - 1:
			k = ord(s[i]) - ord(s[i - 1])
			l = ord(s[i]) - ord(s[i + 1])
			if k < 1:
				k = k * -1
			k = k % 24
			if l < 1:
				l = l * -1
			l = l % 24
			if k != 1 or l != 1:
				return 'NO'
			i += 1
		return 'YES'


class Solution:

	def isGoodString(self, s):
		for i in range(len(s) - 1):
			x = abs(ord(s[i]) - ord(s[i + 1]))
			if x != 1 and 26 - x != 1:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		flag = True
		for i in range(len(s) - 1):
			if abs(ord(s[i]) - ord(s[i + 1])) == 1:
				flag = True
			elif s[i] == 'z' and s[i + 1] == 'a' or (s[i] == 'a' and s[i + 1] == 'z'):
				flag = True
			else:
				flag = False
				break
		if flag == True:
			return 'YES'
		else:
			return 'NO'


class Solution:

	def isGoodString(self, s):
		size = len(s) - 1
		i = 0
		while i < size:
			distance = abs(ord(s[i]) - ord(s[i + 1]))
			if distance > 1 and distance < 25:
				return 'NO'
			if distance == 0:
				return 'NO'
			i += 1
		return 'YES'


class Solution:

	def isGoodString(self, s):
		for i in range(len(s) - 1):
			if abs(ord(s[i]) - ord(s[i + 1])) != 1 and s[i:i + 2] != 'az' and (s[i:i + 2] != 'za'):
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		lis = []
		g = [-1, 1]
		h = [25, -25]
		for i in range(0, len(s) - 1):
			if ord(s[i]) - ord(s[i + 1]) in g:
				lis.append(True)
			elif ord(s[i]) - ord(s[i + 1]) in h:
				lis.append(True)
			else:
				lis.append(False)
		if all(lis):
			return 'YES'
		else:
			return 'NO'


class Solution:

	def isGoodString(self, s):
		for i in range(len(s) - 1):
			if s[i] == s[i + 1]:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		a = 'abcdefghijklmnopqrstuvwxyza'
		d = {}
		e = {}
		for i in range(26):
			k = a[i]
			v = a[i + 1]
			d[k] = v
		for i in range(1, 27):
			k = a[i]
			v = a[i - 1]
			e[k] = v
		for i in range(len(s) - 1):
			a = s[i]
			b = s[i + 1]
			if b != d[a] and b != e[a]:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		k = 1
		if len(s) == 1:
			return 'YES'
		for i in range(len(s) - 1):
			if ord(s[i]) + 1 == ord(s[i + 1]) or ord(s[i]) - 1 == ord(s[i + 1]):
				k = 1
				continue
			elif s[i] == 'a' and s[i + 1] == 'z' or (s[i] == 'z' and s[i + 1] == 'a'):
				k = 1
				continue
			else:
				k = 0
				break
		if k == 0:
			return 'NO'
		else:
			return 'YES'


class Solution:

	def isGoodString(self, s):
		for i in range(1, len(s)):
			if abs(ord(s[i]) - ord(s[i - 1])) == 1 or abs(ord(s[i]) - ord(s[i - 1])) == 25:
				continue
			else:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		j = 1
		n = len(s)
		while j < n:
			prev = s[j - 1]
			next = s[j]
			dis = abs(ord(prev) - ord(next))
			if dis != 1 and abs(dis - 26) != 1:
				return 'NO'
			j += 1
		return 'YES'


class Solution:

	def isGoodString(self, s):
		x = ord(s[0])
		for i in range(1, len(s)):
			if abs(ord(s[i]) - x) != 1 and abs(ord(s[i]) - x) != 25:
				return 'NO'
			x = ord(s[i])
		return 'YES'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def getDistance(self, char1, char2):
		char1 = char1.lower()
		char2 = char2.lower()
		a = ord('a')
		z = ord('z')
		val1 = abs(ord(char1) - ord(char2))
		if char2 > char1:
			m = ord(char1) - a + 1
			n = z - ord(char2)
			val2 = m + n
		else:
			m = ord(char2) - a + 1
			n = z - ord(char1)
			val2 = m + n
		if min(val1, val2) == 1:
			return True
		return False

	def isGoodString(self, s):
		for i in range(len(s)):
			if i < len(s) - 1:
				if not self.getDistance(s[i], s[i + 1]):
					return 'NO'
		return 'YES'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def isGoodString(self, s):
		flag = 'NO'
		res = []
		for i in range(len(s) - 1):
			if ord(s[i]) + 1 == ord(s[i + 1]) or ord(s[i]) - 1 == ord(s[i + 1]) or (s[i] == 'a' and s[i + 1] == 'z') or (s[i] == 'z' and s[i + 1] == 'a'):
				res.append(1)
			else:
				res.append(0)
		if 0 not in res:
			flag = 'YES'
		return flag
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def isGoodString(self, s):
		for i in range(1, len(s)):
			x = ord(s[i - 1])
			y = ord(s[i])
			xxx = abs(x - y) % 24
			if xxx != 1:
				return 'NO'
		return 'YES'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def isGoodString(self, s):
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				return 'NO'
		return 'YES'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def isGoodString(self, s):
		n = len(s)
		for i in range(n - 1):
			d = abs(ord(s[i]) - ord(s[i + 1]))
			if d == 25:
				continue
			if d != 1:
				return 'NO'
		return 'YES'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		s = input()
		solObj = Solution()
		ans = solObj.isGoodString(s)
		print(ans)


class Solution:

	def isGoodString(self, s):
		n = len(s)
		for i in range(0, n - 1):
			diff = abs(ord(s[i]) - ord(s[i + 1]))
			if diff != 1 and 26 - diff != 1:
				return 'NO'
		return 'YES'


class Solution:

	def isGoodString(self, s):
		x = False
		if len(s) == 1:
			return 'YES'
		for i in range(len(s) - 1):
			ch1 = s[i]
			ch2 = s[i + 1]
			d = abs(ord(ch1) - ord(ch2))
			if d > 13:
				d = 26 - d
			if d == 1:
				x = True
			else:
				x = False
				break
		if x == True:
			return 'YES'
		else:
			return 'NO'