Hackerrank: Minimum Absolute Difference in an Array Solution
1function minimumAbsoluteDifference(arr) {2 const N = arr.length3 arr.sort((a, b) => a - b)4 let min = Infinity5 for (let i = 0; i < N - 1; i++) {6 min = Math.min(min, Math.abs(arr[i] - arr[i + 1]))7 }8 return min9}
Comments
Loading comments...
Tags
hackerrank
greedy
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Hackerrank: Max Array Sum
Jan 30, 2021
Previous Post
Hackerrank: Pairs
Jan 30, 2021