Given a string, determine whether every character appears an even number of times.
Problem
You are given a string consisting of lowercase Latin letters. Decide whether each distinct character occurs an even number of times in the string.
Return YES if all character frequencies are even, otherwise return NO.
Notes
- A character may appear zero times, one time, or many times.
- You only need to check the parity of each frequency, not the exact counts.
Input Format
- A single string
s.
Output Format
- Print
YESif every character insappears an even number of times. - Otherwise print
NO.
Constraints
1 <= |s| <= $10^{5}$scontains only lowercase English letters.
Hints
- Count how many times each letter appears.
- Alternatively, track whether each count is even or odd as you scan the string.
Input Format
A single lowercase string s.
Output Format
Print YES if all character frequencies are even, otherwise print NO.
Constraints
1 <= |s| <= $10^{5}$scontains only lowercase English letters.
Example 1
Input
aabb
Output
YES
Explanation
a appears 2 times and b appears 2 times, so every frequency is even.
Example 2
Input
abac
Output
NO
Explanation
a appears 2 times, but b and c appear once each, so not all frequencies are even.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.