BackeasyStrings

Perfect Pairable String Solution

Problem Statement

Given a string s consisting of lowercase English letters, determine if the characters of the string can be partitioned into pairs of identical characters such that every single character in the string belongs to exactly one pair. This requires every unique character in the string to have an even frequency of occurrence.

Example 1
Input
s = "aabbcc"
Output
true

Explanation: The characters can be paired as ('a', 'a'), ('b', 'b'), and ('c', 'c'). Every character is successfully paired.

Example 2
Input
s = "abcab"
Output
false

Explanation: The frequencies of the characters are 'a': 2, 'b': 2, and 'c': 1. Since 'c' has an odd frequency, it cannot be paired.

Constraints

  • 1 <= s.length <= 10^5
  • s consists only of lowercase English letters.
Live Compiler
Sign InSign Up
Loading...
Test Cases & Output
Click "Run" to execute