Solved LeetCode program · 76 of 1,000
#0076 · Minimum Window Substring
Original English source
The source is "ADOBECODEBANC". The target is "ABC". The sourcelast is the last position of source. The targetlast is the last position of target. The need is an empty map.
For every position from 0 to targetlast.
The symbol is character position of target. Add 1 to entry symbol of need.
The window is an empty map. The required is the number of entries in need. The formed is 0. The left is 0. The beststart is 0. The bestlength is 1000000.
For every right from 0 to sourcelast.
The symbol is character right of source. Add 1 to entry symbol of window. If need has entry symbol and entry symbol of window is entry symbol of need, add 1 to formed.
Repeat while formed is required.
The width is right minus left plus 1. If width is less than bestlength, set beststart to left, set bestlength to width. The mark is character left of source. Subtract 1 from entry mark of window. If need has entry mark and entry mark of window is less than entry mark of need, subtract 1 from formed. Add 1 to left.
The finish is beststart plus bestlength. The answer is the slice of source from beststart to finish. Display answer.
Expected stdout
BANC