The TransCompilator

Solved LeetCode program · 855 of 1,000

#1147 · Longest Chunked Palindrome Decomposition

Hard String chunk-18.md

Original English source

Keep a shared text as empty text. Place "ghiabcdefhelloadamhelloabcdefghi" into text. Keep a shared left of 0. Keep a shared right of the last position of text. Keep a shared pieces of 0. Keep a shared found of 0.

To seek. Set found to 0. The reach is (right minus left plus 1) divided by 2.
For every span from 1 to reach.
The front is the slice of text from left to left plus span. The back is the slice of text from right minus span plus 1 to right plus 1. The equal is 0. If front matches back, set equal to 1. If equal is 1 and found is 0, add 2 to pieces, set left to left plus span, set right to right minus span, set found to 1, stop.

Repeat while left is at most right.
If left is right, add 1 to pieces, set left to right plus 1, stop. Seek. If found is 0, add 1 to pieces, set left to right plus 1.

Show pieces.

Open in Playground Browse all 1,000 problems

Expected stdout

7