Firstly, we will find the number of distinct characters. Then we keep on traversing through the string, If the length of substring is equal to max distinct characters we try to reduce its length from the beginning. Else, we will increment at the end such that the pointer never exceeds the string length.