HackerRank C++: Minimum Absolute Difference in Array (greedy algorithm solution)

preview_player
Показать описание
HackerRank C++ solution for the Greedy Algorithm coding challenge called Minimum Absolute Difference in an Array. This C++ greedy algorithm runs in linear time, O(n), and it makes use of the abs() function from the cstdlib and cmath headers to get the absolute difference between two elements in an array. After looping through the array and finding minimum absolute difference, we return it as an integer. That is the global optimum.

Рекомендации по теме
Комментарии
Автор

Ur method of explanation is much better

dipeshjha
Автор

Good explanation! Thanks, I was really stuck on this one!

diveinsidetech
Автор

i did the same method as you but instead of using function sort, i sorted it normally with 2 for-loops and encounter "time exceed" situation :((((

anhtuanmai