Answer: MEESHO SUPPLY Hiring | Minimum Absolute Difference |Off-Campus OA (2021)
Answer · Posted Jun 2026
Approach The minimum absolute difference must occur between two adjacent elements in the sorted array. Steps: Sort the array. Find the minimum difference between adjacent elements. Traverse again and collect all pairs having that difference. Strategy Sort the array. Compute minDiff. Add every adjacent pair whose difference equals minDiff. Java Solution: import java.util.*; class Solution { public List<List<Integer>> minimumAbsDifference(int[] arr) { Arrays.sort(arr); int minDiff = Integer.MAX_VALUE; List<List<Integer>> result = new ArrayList<>(); for (int i = 1; i < arr.length; i++) ...
The full answer & interview discussion are available to premium members.
Log in Create a free account