Interview Query

Minimum Absolute Distance

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments (26)
Next question

Given an array of integers, write a function min_distance to calculate the minimum absolute distance between two elements then return all pairs having that absolute difference.

Note: Make sure to return the pairs in ascending order.

Example:

Input:

v = [3, 12, 126, 44, 52, 57, 144, 61, 68, 72, 122]

Output:

def min_distance(V) ->

min = 4

[[57, 61], [68, 72], [122, 126]]
.
.
.
.
.


Comments

Loading comments