It is the classical algorithm called find smallest substring containing all keys. I have practice the algorithm over ten times last 12 months. I learn so many things through the practice, and it is my most favorite algorithm.
I wrote an algorithm using exactly same idea to apply to integer array.
Here is my C# code.
Follow up after mock interview
It took me a while to write and simplify the code from line 60 to line 66 during mock interview. What I did is to go over in detail if the left char of sliding windows is not in the dictionary, or in the dictionary. And then discuss one step a time.
Other way to think to expedite the process is asking myself four critical question:
1. When to break the while loop 51?
2. When to decrease the variable numbersFound
3. when to decrease the dictionary for the key if the left char is in the dictionary
4. Please move the left point one step forward to start a new sliding window