10

I think I understood your problem. Problem description Given: num_items - the number of available items targets - a list of potential targets, each having a value threshold - a cutoff limit Task: Choose the first num_items elements of targets, whose values are above or equal to threshold. Return the array index of the last chosen element from targets (...


6

@Finomnis offers an excellent theoretical and algorithmic analysis. As is my wont, I'll take a different approach and examine your usage of Python. counter = 0 break does not need the counter assignment at all. You're breaking, so you will return to the top of the outer loop where this assignment is done the first time; it ...


4

Avoid double pointers. They are absolutely unwarranted in all the functions (except init, but see below). Prefer returning a value to a side effect. In the client code, which I presume is along the lines of struct priority_queue * pq; init_queue(&pq, capacity); I have to read the source of init_queue to see that there is a side effect of modifying ...


4

Naming The name Heap is confusing, since this is a priority queue, not a heap. The heap is merely an internal private implementation detail that should not be exposed to the outside world. Just call it what it is: a PriorityQueue. The same applies to heap. This one is a local variable with limited scope and obvious semantics, so I would be fine with pq as a ...


3

public int Length { get; private set; } _elements carries the length already, and duplicate state that you keep in sync manually is a good way to create bugs. Consider implementing the getter as returning _elements.Count, and not having a setter. That way it is impossible for the length to ever be wrong, instead of it being possible but hopefully avoided ...


2

in function: void init_queue(struct priority_queue **pq, size_t capacity) after the final closing brace '}' there is a semicolon ';'. This results in the compiler outputting: untitled1.c:41:2: warning: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic] There are also some warnings about implicit conversions. When compiling, always enable ...


2

Formatting The code formatting is fairly consistent in terms of line terminators, though there are a couple lines missing semi-colons - e.g. in swim() and sink(). While they are not always required it is best to be consistent. Method without return value The isEmpty method has no return keyword, nor any side effects: isEmpty() { this.n === 0; } ...


Only top voted, non community-wiki answers of a minimum length are eligible