Solved LeetCode program · 756 of 1,000
#0992 · Subarrays with K Different Integers
Original English source
Keep a shared numbers holding 1, 2, 1, 2, and 3. Keep a shared counts as a list of 6 zeros. Keep a shared limit of 0. Keep a shared beginning of 0. Keep a shared distinct of 0. Keep a shared total of 0. Keep a shared window of 0.
To wipe. For every spot from 0 to 5, set item spot of counts to 0.
To tighten from right (a whole number).
Repeat while distinct is more than limit.
The position is beginning. The old is item position of numbers. Decrease item old of counts by 1. If item old of counts is 0, set distinct to distinct minus 1. Increase beginning by 1. Set window to right minus beginning plus 1.
To tally with bound (a whole number). Set limit to bound. Wipe. Set total to 0. Set beginning to 0. Set distinct to 0.
For every right from 0 to 4.
The value is item right of numbers. If item value of counts is 0, add 1 to distinct. Increase item value of counts by 1. Set window to right minus beginning plus 1. Tighten from right. Increase total by window.
Tally with 2. The high is total. Tally with 1. The low is total. Show high minus low.
Expected stdout
7