Array ( [0] => [1] => questions [2] => Basic [3] => Super-ASCII-String-Checker ) Codevita Previous Questions | Super ASCII String Checker | THE INQUISITIVE





Super ASCII String Checker

LEVEL:Beginner

Description

In the Byteland country a string 'S' is said to super ascii string if and only if count of each character in the string is equal to its ascii value.
In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.
Your task is to find out whether the given string is a super ascii string or not.

Input Format

First line contains number of test cases T, followed by T lines, each containing a string "S".
Constraints:
1<=T<=100
1<=|S|<=400, S will contains only lower case alphabets ('a'-'z').

Output Format

For each test case print "Yes" if the String "S" is super ascii, else print "No"


Example 1:

Input
2
bba
scca
Output
Yes
No
Example 2:

Input
2
bbaa
ddddccca
Output
No
Yes
Example 3:

Input
2
bbaa
scca
Output
No
No

oops

Login to see Discussion




Approach

Maintaining a count array, which stores the count of the characters at their (ascii-1) positions. At last iterate through the count array, by maintaining a flag value, if the count at that position is greater than the ascii, set the flag to '0' and break the loop.


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution