Parity of Strings
InterviewTime limit1sMemory limit1024 MB
Given a lowercase string, decide whether every letter appears an even number of times, every letter appears an odd number of times, or neither.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
The historical battle between numbers and strings has taken a new twist. Numbers brag about being classified as 'even' or 'odd', while strings lack such a feature. But don't count strings out yet!
A string is 'even' if every letter in it appears an even number of times. A string is 'odd' if every letter in it appears an odd number of times.
Given a string, determine whether it is even, odd, or neither.
Input
The input is a single line, starting in column 1 and not exceeding column 70. It contains only lowercase letters, and there is at least one letter.
Output
Print a single integer. Print 0 if the string is even, 1 if the string is odd, or 2 if the string is neither.