• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 06, 2023 |2.5K Views
PROBLEM OF THE DAY: 05/10/2023 | Count number of substrings
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Strings but will also help you build up problem-solving skills.

In this problem, we are given, a string of lowercase alphabets, count all possible substrings (not necessarily distinct) that have exactly k distinct characters.

Example :

Input:
S = "aba", K = 2
Output:
3

Explanation:
The substrings are: "ab", "ba" and "aba".

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/count-number-of-substrings4528/1
Solution IDE LInk: https://ide.geeksforgeeks.org/online-cpp-compiler/201508fb-29c3-4e7c-a0ad-a19a3af16ccc