The TransCompilator

Solved LeetCode program · 511 of 1,000

#0719 · Find K-th Smallest Pair Distance

Hard Array chunk-11.md

Original English source

Keep a shared numbers holding 1, 3, and 1. Keep a shared wanted of 1. Keep a shared finish of 0. Keep a shared bottom of 0. Keep a shared top of 0. Keep a shared answer of 0. Keep a shared tally of 0. Keep a shared front of 0. Sort numbers. Set finish to the last position of numbers. The endpoint is finish. Set top to item endpoint of numbers minus item 0 of numbers. Set answer to top.

To retreat from right (a whole number) with middle (a whole number). The spot is front. If item right of numbers minus item spot of numbers is at most middle, return. Add 1 to front. Retreat from right with middle.

To measure from middle (a whole number). Set tally to 0. Set front to 0.
For every right from 0 to finish.
Retreat from right with middle. Increase tally by right minus front.

Repeat while bottom is at most top.
The middle is the midpoint of bottom and top. Measure from middle. If tally is at least wanted, set answer to middle, set top to middle minus 1. If tally is less than wanted, set bottom to middle plus 1.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

0