Dsa
Sliding Window
Warm-up
First Unique Character in Substring
Given a string `s`, find the first unique character in a substring of length `k`. If there is no such character, return `-1`.
Input Format:
- The first line contains the string `s` (1 <= |s| <= 10000).
- The second line contains the integer `k` (1 <= k <= |s|).
Output Format:
- Print the character that is the first unique character in the substring of length `k`, or `-1` if none exists.
Example:
Input:
abbaaa
3
Output:
a
(The substring "abb" contains the first unique character 'a'.)
Key concepts
sliding_windowstringshashmap
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