You are viewing a single comment's thread. Return to all comments →
int minimumAbsoluteDifference(int n, vector <int> arr) { sort(arr.begin(), arr.end()); int min = abs(arr[1]-arr[0]); for (int i = 1; i < arr.size() - 1; i++) { if (abs(arr[i+1] - arr[i]) < min) min = abs(arr[i+1] - arr[i]); } return min; }
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 →