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.
bcoz, sorting of array will bring small value element near, thus their diff also min.
suppose if didn't apply sort..
ex.
n = 4
arr = 2 34 68 1
in this case 2 and 1 are not near so their diff will not be calaculate by the loop(as per ur logic).
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 →
bcoz, sorting of array will bring small value element near, thus their diff also min.
suppose if didn't apply sort.. ex. n = 4 arr = 2 34 68 1 in this case 2 and 1 are not near so their diff will not be calaculate by the loop(as per ur logic).