Dsa
Sliding Window
Easy
Rotate Characters in a String
Given a string `s`, return the number of characters that need to be changed to make every substring of length `k` unique. If the substring contains duplicate characters, all duplicates need to be modified to ensure uniqueness within that substring.
### Input Format:
- A single line containing the string `s` (1 <= |s| <= 1000).
- An integer `k` (1 <= k <= |s|).
### Output Format:
- Output a single integer representing the total number of character changes needed.
### Example:
Input:
abcabc 3
Output:
3
### Explanation:
In the substring 'abc', all characters are unique, but in 'abc' (the second occurrence), 'a' and 'b' repeat and need to be changed.
Key concepts
sliding_windowstringgreedy
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