Dsa
Hashing
Medium
The Parity Window
A string can be rearranged into a palindrome if and only if at most one character appears an odd number of times. Given a string S and an integer K, count how many substrings of length K can be rearranged into a palindrome.
Input Format:
- Line 1: An integer K.
- Line 2: A string S consisting of lowercase English letters.
Output Format:
- An integer representing the count of substrings of length K that are 'palindromic anagrams'.
Example:
Input:
3
aabba
Output:
2
(Explanation: 'aab' can be 'aba', 'abb' can be 'bab', 'bba' can be 'bab' - wait, windows are 'aab', 'abb', 'bba'. 'aab' is ok, 'abb' is ok, 'bba' is ok. Total 3? No, sample input: 3, aabba. Windows: aab, abb, bba. All 3 are valid.)
Key concepts
hashingbitmaskingsliding-window
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now