We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My Java solution with o(n log n + n) time complexity and o(1) space:
publicstaticintminimumAbsoluteDifference(List<Integer>arr){// goal: determine the min abs val between any two pairs in arrCollections.sort(arr);//sort arr ascendingintmin=Integer.MAX_VALUE;for(inti=1;i<arr.size();i++){intcurrentMin=arr.get(i)-arr.get(i-1);if(currentMin<min)min=currentMin;}returnmin;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →
My Java solution with o(n log n + n) time complexity and o(1) space: