Dsa
Sliding Window
Easy
Count Distinct Substrings of Length K
Given a string s and an integer k, your task is to count the number of distinct substrings of length k in the string s.
Your program should read a string and an integer from standard input and print the count of distinct substrings of length k.
**Input Format:**
The first line will contain the string s (1 ≤ |s| ≤ 10^5).
The second line will contain an integer k (1 ≤ k ≤ |s|).
**Output Format:**
An integer representing the count of distinct substrings of length k.
**Example:**
Input:
banana
3
Output:
4
Distinct substrings of length 3 in "banana" are: "ban", "ana", "nan", and "aba".
Key concepts
sliding_windowstringset
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