|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-time-to-build-blocks "Minimum Time to Build Blocks") |
| 9 | + |
| 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/ugly-number-iii "Ugly Number III") |
| 11 | + |
| 12 | +## [1200. Minimum Absolute Difference (Easy)](https://leetcode.com/problems/minimum-absolute-difference "") |
| 13 | + |
| 14 | +<p>Given an array of <strong>distinct</strong> integers <code>arr</code>, find all pairs of elements with the minimum absolute difference of any two elements. </p> |
| 15 | + |
| 16 | +<p>Return a list of pairs in ascending order(with respect to pairs), each pair <code>[a, b]</code> follows</p> |
| 17 | + |
| 18 | +<ul> |
| 19 | + <li><code>a, b</code> are from <code>arr</code></li> |
| 20 | + <li><code>a < b</code></li> |
| 21 | + <li><code>b - a</code> equals to the minimum absolute difference of any two elements in <code>arr</code></li> |
| 22 | +</ul> |
| 23 | + |
| 24 | +<p> </p> |
| 25 | +<p><strong>Example 1:</strong></p> |
| 26 | + |
| 27 | +<pre> |
| 28 | +<strong>Input:</strong> arr = [4,2,1,3] |
| 29 | +<strong>Output:</strong> [[1,2],[2,3],[3,4]] |
| 30 | +<strong>Explanation: </strong>The minimum absolute difference is 1. List all pairs with difference equal to 1 in ascending order.</pre> |
| 31 | + |
| 32 | +<p><strong>Example 2:</strong></p> |
| 33 | + |
| 34 | +<pre> |
| 35 | +<strong>Input:</strong> arr = [1,3,6,10,15] |
| 36 | +<strong>Output:</strong> [[1,3]] |
| 37 | +</pre> |
| 38 | + |
| 39 | +<p><strong>Example 3:</strong></p> |
| 40 | + |
| 41 | +<pre> |
| 42 | +<strong>Input:</strong> arr = [3,8,-10,23,19,-4,-14,27] |
| 43 | +<strong>Output:</strong> [[-14,-10],[19,23],[23,27]] |
| 44 | +</pre> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | +<p><strong>Constraints:</strong></p> |
| 48 | + |
| 49 | +<ul> |
| 50 | + <li><code>2 <= arr.length <= 10^5</code></li> |
| 51 | + <li><code>-10^6 <= arr[i] <= 10^6</code></li> |
| 52 | +</ul> |
| 53 | + |
| 54 | +### Related Topics |
| 55 | + [[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)] |
| 56 | + |
| 57 | +### Hints |
| 58 | +<details> |
| 59 | +<summary>Hint 1</summary> |
| 60 | +Find the minimum absolute difference between two elements in the array. |
| 61 | +</details> |
| 62 | + |
| 63 | +<details> |
| 64 | +<summary>Hint 2</summary> |
| 65 | +The minimum absolute difference must be a difference between two consecutive elements in the sorted array. |
| 66 | +</details> |
0 commit comments