The TransCompilator

Solved LeetCode program · 882 of 1,000

#1208 · Get Equal Substrings Within Budget

Medium String chunk-18.md

Original English source

Keep a shared alphabet as empty text. Place "abcdefghijklmnopqrstuvwxyz" into alphabet. Keep a shared symbol as empty text. Keep a shared position of 0.

To locate from spot (a whole number). The letter is the slice of alphabet from spot to spot plus 1. If letter matches symbol, set position to spot, return. Locate from spot plus 1.

Keep a shared costs as an empty list of whole numbers. Keep a shared total of 0. Keep a shared left of 0. Keep a shared budget of 0. Keep a shared best of 0. Set budget to 3.

The first is "abcd". The second is "bcdf". The last is the last position of first.
For every spot from 0 to last.
The piece is the slice of first from spot to spot plus 1. Set symbol to piece. Locate from 0. The leftspot is position. The other is the slice of second from spot to spot plus 1. Set symbol to other. Locate from 0. The gap is leftspot minus position. If gap is less than 0, set gap to 0 minus gap. Place gap into costs.

To shrink from spot (a whole number).
Repeat while total is more than budget.
Decrease total by item spot of costs. Add 1 to spot. Set left to spot.

For every right from 0 to last.
Increase total by item right of costs. Shrink from left. The width is right minus left plus 1. If width is more than best, set best to width.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

3