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.
Minimum Absolute Difference in an Array
Minimum Absolute Difference in an Array
Sort by
recency
|
686 Discussions
|
Please Login in order to post a comment
How can we do this without sorting first while not timing out?
Python:
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to git a star :) )
Python
I have looked up some codes in here and found 2 common solutions: using loop-nest or sort and check adjacent elements. I came up with using Insertion sort as an idea to both sort and check minimum abs difference. The idea is to control the break point and reduce the amount of comparision (comparing to loop-nest). However, it result in running out of time for the last case. Can someone explain?