Smallest window of "adobecodebanc" containing every character of "abc" (with multiplicity). need counts what is still missing. Grow the window with r until nothing is missing, then shrink with l for as long as it stays covered, remembering the shortest window seen.
Minimum window covering 3 characters.
r = 0, 'a' enters. It was still needed, so missing drops to 2.
Right 0 is a, missing 2.
r = 1, 'd' enters. Not a wanted character, so missing stays at 2.
Right 1 is d, missing 2.
r = 2, 'o' enters. Not a wanted character, so missing stays at 2.
Right 2 is o, missing 2.
r = 3, 'b' enters. It was still needed, so missing drops to 1.
Right 3 is b, missing 1.
r = 4, 'e' enters. Not a wanted character, so missing stays at 1.
Right 4 is e, missing 1.
r = 5, 'c' enters. It was still needed, so missing drops to 0. Everything is covered.
Right 5 is c, missing 0.
Window "adobec" of length 6 is the best so far. Shrink: 'a' leaves from the left. It was needed, so the window is no longer covered (missing 1) and r must move again.
Left moves to 1, missing 1.
r = 6, 'o' enters. Not a wanted character, so missing stays at 1.
Right 6 is o, missing 1.
r = 7, 'd' enters. Not a wanted character, so missing stays at 1.
Right 7 is d, missing 1.
r = 8, 'e' enters. Not a wanted character, so missing stays at 1.
Right 8 is e, missing 1.
r = 9, 'b' enters. The window already had enough of it, so missing stays at 1.
Right 9 is b, missing 1.
r = 10, 'a' enters. It was still needed, so missing drops to 0. Everything is covered.
Right 10 is a, missing 0.
Shrink: 'd' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 2, missing 0.
Shrink: 'o' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 3, missing 0.
Shrink: 'b' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 4, missing 0.
Shrink: 'e' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 5, missing 0.
Shrink: 'c' leaves from the left. It was needed, so the window is no longer covered (missing 1) and r must move again.
Left moves to 6, missing 1.
r = 11, 'n' enters. Not a wanted character, so missing stays at 1.
Right 11 is n, missing 1.
r = 12, 'c' enters. It was still needed, so missing drops to 0. Everything is covered.
Right 12 is c, missing 0.
Shrink: 'o' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 7, missing 0.
Shrink: 'd' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 8, missing 0.
Window "ebanc" of length 5 is the best so far. Shrink: 'e' leaves from the left. It was surplus, so the window is still covered and can shrink further.
Left moves to 9, missing 0.
Window "banc" of length 4 is the best so far. Shrink: 'b' leaves from the left. It was needed, so the window is no longer covered (missing 1) and r must move again.
Left moves to 10, missing 1.
Smallest covering window: "banc", length 4. Each edge moves only forward, so the scan is O(n) plus the alphabet for the counts.
Best window banc.