The TransCompilator

Solved LeetCode program · 57 of 1,000

#0057 · Insert Interval

Medium Array chunk-02.md

Original English source

The begins is a list of 1 and 6. The finishes is a list of 3 and 9. Place 2 into begins. Place 5 into finishes. The last is the last position of begins.
For every left from 0 to last.
For every right from left to last.
If item right of begins is less than item left of begins, swap item left of begins and item right of begins, swap item left of finishes and item right of finishes.

The outbegins is an empty list of whole numbers. The outfinishes is an empty list of whole numbers.
For every position from 0 to last.
The start is item position of begins. The finish is item position of finishes. The size is the number of items in outbegins. If size is 0, Place start into outbegins, Place finish into outfinishes. If size is more than 0 and start is at most item (size minus 1) of outfinishes and finish is more than item (size minus 1) of outfinishes, set item (size minus 1) of outfinishes to finish. If size is more than 0 and start is more than item (size minus 1) of outfinishes, Place start into outbegins, Place finish into outfinishes.

The count is the number of items in outbegins. The final is count minus 1.
For every position from 0 to final.
Show item position of outbegins. Show item position of outfinishes. Show "---".

Open in Playground Browse all 1,000 problems

Expected stdout

1
5
---
6
9
---