def delete_from_heap(array, new_array):
    """
    Delete from heap
    Complexity: O(logN)
    """
    array[0], array[len(array)-1] = array[len(array)-1], array[0]
    left_child = 1
    right_child = 2
    max_index = 0
    current_index = 0
    new_array.append(array.pop())

    while True:
        if left_child < len(array):
            if array[max_index] < array[left_child]:
                max_index = left_child

        if right_child < len(array):
            if array[max_index] < array[right_child]:
                max_index = right_child

        if max_index != current_index:
            array[max_index], array[current_index] = array[current_index], array[max_index]
            current_index = max_index
            left_child = 2*max_index + 1
            right_child = 2*max_index + 2
        else:
            break

    return new_array