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.
The values that are closest to one another are the ones that will have the least difference.
After sorting I know that for any value, i , the values at i-1 and i+1 are
closest to i.Therefore, I dont have to consider all pairs that contain, i, I can just consider the ones that are going to yield the least difference, i's neighbors. Everyone else is farther away.
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 →
The values that are closest to one another are the ones that will have the least difference.
After sorting I know that for any value, i , the values at i-1 and i+1 are closest to i.Therefore, I dont have to consider all pairs that contain, i, I can just consider the ones that are going to yield the least difference, i's neighbors. Everyone else is farther away.