You are given a string of lowercase characters. A magic number M is the summation of the count of characters that occupy even positions in English alphabets and have even frequency, and the count of characters that occupy odd positions in English alphabets and have an odd frequency.
You have to return “EVEN” if M is even, otherwise return “ODD”.
For example:
If we are given a string ‘aabb’.Then we can see the frequency of a=2 and b=2. The position of ‘a’ in alphabets is 1 and the position of ‘b’ is 2. So ‘a’ has an even frequency but its position is odd, so it will not contribute to M. As ‘b’ has an even frequency and its position is also even, so M=1. Now M =1 which is odd, so we have to return “ODD”.
Input Format :
The first line of input contains a single integer 'T', representing the number of test cases. The 'T' test cases follow.
The first and only line of each test case contains a string 'STR'.
Output format :
For each test case, print “EVEN” if M is even, else return “ODD” without quotes.
Note :
You don’t have to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 100
1 <= N <= 10 ^ 4
Time limit: 1 sec
3
abbadef
bbbb
xyz
EVEN
ODD
ODD
(i) For the first string M=2 which is even.
(ii) For the second string M=1 which is odd.
(iii) For the third string M=1 which is odd.
3
abbc
bbdddd
z
ODD
EVEN
EVEN
(i) For the first string M=3 which is odd.
(ii) For the second string M=2 which is even.
(iii) For the third string M=0 which is even.
Think about iterating over the whole string and find the frequency of each character.
We will find the frequency of all characters by iterating over the whole string 26 times. On completion of iteration if the frequency of character is odd and the position of the character is odd, increase M by 1, otherwise if the frequency of character is even and the position of the character is even, increase M by 1.
O(N), where ‘N’ is the length of the string.
As for each character we are iterating over the whole string 26 times so time complexity is O(N*26).
O(1).
As we are not using any extra memory.