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 Arrays but also build up problem-solving skills.
In this problem, given a string S consisting of the characters 0, 1 and 2. Your task is to find t
he length of the smallest substring of string S that contains all the three characters 0, 1 and 2. If no such substring exists, then return -1.Example :
Input:
S = 10212
Output:
3
Explanation:
The substring 102 is the smallest substring that contains the characters 0, 1 and 2.
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems-preview/smallest-window-containing-0-1-and-2--170637/1