The TransCompilator

Solved LeetCode program · 858 of 1,000

#1156 · Swap For Longest Repeated Character Substring

Medium String chunk-18.md

Original English source

Keep a shared text as empty text. Place "aaabaaa" into text. Keep a shared wanted as empty text. Keep a shared total of 0. Keep a shared best of 0. Keep a shared lastindex of the last position of text.
To tally from spot (a whole number). If spot is more than lastindex, return. If the slice of text from spot to spot plus 1 matches wanted, add 1 to total. Tally from spot plus 1.

To scan from seed (a whole number). Set wanted to the slice of text from seed to seed plus 1. Set total to 0. Tally from 0.
For every start from 0 to lastindex.
The matching is 0.
For every finish from start to lastindex.
If the slice of text from finish to finish plus 1 matches wanted, add 1 to matching. The span is finish minus start plus 1. The spare is total minus matching. The cap is total. If spare is more than 0, set cap to total plus 1. The candidate is span. If candidate is more than cap, set candidate to cap. If span minus matching is at most 1 and candidate is more than best, set best to candidate.

For every seed from 0 to lastindex.
Scan from seed.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

6