LeetCode 1200: Minimum Absolute Difference in Array

Hello Everyone, Day 26 / #100DaysOfCode LeetCode 1200 — Minimum Absolute Difference (Easy) Problem (short): Given an array of distinct integers, find all pairs [a, b] such that |a - b| is minimum among all possible pairs. Key Insight: After sorting, the minimum absolute difference can only occur between adjacent elements. Why? - Any non-adjacent pair will have a larger gap due to sorting. - So instead of checking all O(n²) pairs, we only scan once. Approach: 1. Sort the array 2. Traverse from left to right 3. Track the smallest difference between arr[i] and arr[i-1] 4. Reset the result list when a smaller diff is found 5. Append pairs when the diff matches the current minimum Complexity: - Time: O(n log n) (sorting) - Space: O(1) extra (excluding output) #Leetcode #DSA #Java

  • text

To view or add a comment, sign in

Explore content categories