Welcome to the daily solving of our PROBLEM OF THE DAY with Siddharth Hazra. 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 Two-Pointers but will also help you build up problem-solving skills.
In this video, we are given a string you need to print the size of the longest possible substring that has exactly K unique characters. If there is no possible substring then print -1.
Example :
Input:
S = "aabacbebebe", K = 3
Output:
7
Explanation:
"cbebebe" is the longest substring with 3 distinct characters
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/longest-k-unique-characters-substring0853/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/9ad17abb-5c98-4ac5-b218-2208ea964d71