The TransCompilator

Solved LeetCode program · 345 of 1,000

#0467 · Unique Substrings in Wraparound String

Medium String chunk-07.md

Original English source

Keep a shared word as empty text. Place "zab" into word. Keep a shared alphabet as empty text. Place "abcdefghijklmnopqrstuvwxyz" into alphabet. Keep a shared target as empty text. Keep a shared foundat of 0.
To locate from spot (a whole number). If spot is more than 25, return. The symbol is the slice of alphabet from spot to spot plus 1. If symbol matches target, set foundat to spot, return. Locate from spot plus 1.

Keep a shared piece as empty text. Keep a shared run of 1. Keep a shared nextindex of 0. Keep a shared expected as empty text.
To step from spot (a whole number). If spot is 0, return. Set piece to the slice of word from spot to spot plus 1. Set target to the slice of word from spot minus 1 to spot. Set foundat to -1. Locate from 0. Set nextindex to foundat plus 1. If nextindex is 26, set nextindex to 0. Set expected to the slice of alphabet from nextindex to nextindex plus 1. If piece matches expected, add 1 to run, return. Set run to 1.

Keep a shared letters as an empty list of text. Keep a shared bests as an empty list of whole numbers. Keep a shared spotfound of 0.
To record from spot (a whole number). If spot is more than the last position of letters, return. If item spot of letters matches piece, set spotfound to spot, return. Record from spot plus 1.

To lift from spot (a whole number). If run is more than item spot of bests, set item spot of bests to run.

The last is the last position of word.
For every spot from 0 to last.
If spot is more than 0, step from spot. Set piece to the slice of word from spot to spot plus 1. Set spotfound to -1. Record from 0. If spotfound is less than 0, Place piece into letters, Place run into bests. If spotfound is at least 0, lift from spotfound.

The total is 0.
For each value in bests.
Add value to total.

Show total.

Open in Playground Browse all 1,000 problems

Expected stdout

6