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.
In this case, if the "list by comprehension" to which you refer is presumably that which is inside the min function, then your assertion is false.
Here in Python3, a generator is being passed to the min function, so no list is being created in memory for it. Elements are being discovered through lazy evaluation of the formula. The minimum is a greedy operation running over the indices i, so it does not store the previous values a[i+1]-a[i] as it proceeds forward. It just finds the minimum up to that point when the i-th term is considered.
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 →
In this case, if the "list by comprehension" to which you refer is presumably that which is inside the
min
function, then your assertion is false.Here in Python3, a generator is being passed to the
min
function, so no list is being created in memory for it. Elements are being discovered through lazy evaluation of the formula. The minimum is a greedy operation running over the indicesi
, so it does not store the previous valuesa[i+1]-a[i]
as it proceeds forward. It just finds the minimum up to that point when thei
-th term is considered.