I have a list (or heap) of elements and I want to replace the element with the lowest value with a new element of higher value. However if there are multiple elements in the heap with this lowest value, I expect to replace the last element.
Example 1 (works as expected):
input: n = 7new_element = 1hlist = [0 for x in range(n)]hp.heapreplace(hlist,new_element)hlistoutput:[0, 0, 0, 0, 0, 0, 1]
Example 2 (doesn't work as expected):
input: n = 10new_element = 1hlist = [0 for x in range(n)]hp.heapreplace(hlist,new_element)hlistoutput:[0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
The expected output is:[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
With n in [1,2,...,9,10] it works when n in [1, 2, 3, 6, 7].