The TransCompilator

Solved LeetCode program · 397 of 1,000

#0532 · K-diff Pairs in an Array

Medium Array chunk-08.md

Original English source

Keep a shared numbers holding 3, 1, 4, 1, and 5. Keep a shared gap of 2. Keep a shared last of 0. Keep a shared pairs of 0. Sort numbers. Set last to the last position of numbers.

To seek from start (a whole number). The target is item start of numbers plus gap.
For every later from start plus 1 to last.
If item later of numbers is target, add 1 to pairs, stop.

For every first from 0 to last.
If first is 0, seek from first. If first is more than 0, If item first of numbers is not item (first minus 1) of numbers, seek from first.

Show pairs.

Open in Playground Browse all 1,000 problems

Expected stdout

2