The TransCompilator

Solved LeetCode program · 457 of 1,000

#0646 · Maximum Length of Pair Chain

Medium Array chunk-10.md

Original English source

Keep a shared begins holding 1, 2, and 3. Keep a shared finishes holding 2, 3, and 4. Keep a shared last of 2. Keep a shared picked of 0.
To seek from candidate (a whole number) with chosen (a whole number). If candidate is more than last, set picked to chosen, return. If item candidate of finishes is less than item chosen of finishes, set chosen to candidate. Seek from candidate plus 1 with chosen.

To place from spot (a whole number). The pick is spot. Seek from spot plus 1 with pick. If picked is not spot, swap item spot of finishes and item picked of finishes, swap item spot of begins and item picked of begins.

For every spot from 0 to last minus 1.
Place from spot.

The count is 0. The lastend is -1000000000.
For every spot from 0 to last.
If item spot of begins is more than lastend, add 1 to count, set lastend to item spot of finishes.

Show count.

Open in Playground Browse all 1,000 problems

Expected stdout

2