How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focusโor scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
๐ง Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
๐ Select Passive to activate
Difficulty: Easy
Topics: Arrays, Sorting
Given an array of distinct integers arr, find all pairs of elements that have the minimum absolute difference among all possible pairs.
Return a list of pairs in ascending order (with respect to pairs), where each pair [a, b] satisfies:
a and b are from arra < bb - a equals the minimum absolute difference in the arrayInput
arr = [4, 2, 1, 3]
Output
[[1,2], [2,3], [3,4]]
Explanation:
The minimum absolute difference is 1, so all pairs with difference 1 are returned.
Input
arr = [1, 3, 6, 10, 15]
Output
[[1,3]]
Input
arr = [3, 8, -10, 23, 19, -4, -14, 27]
Output
[[-14,-10], [19,23], [23,27]]
2 <= arr.length <= 10^5-10^6 <= arr[i] <= 10^6arr are distinctSort the array first.
The minimum absolute difference will always be found between adjacent elements in the sorted array.
๐ฏ Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
๐ Locked steps cannot be moved. Only unlocked steps are draggable.
๐ Enable sound for swap feedback and completion effects.