New answers tagged

2

A class Solution with only public members can be written struct Solution. But with only a single member function (that never uses the this pointer), why not a free function? Presumably your vector is intended to be a std::vector, in which case we need #include <vector> and the correct namespace qualifier. Don't pass a reference to a mutable object ...


-1

Like @200_success pointed out in the comments, your function will never return False. Try to follow the function code in this case: what if you arrive to a node that has no left/right nodes? You will arrive at the end of the function, where there is no return statement. Adding a return False there gives me 100% score. As a recommendation, instead of nesting ...


7

Import import java.util.*; The class does not need to import the whole java.util package. Instead it only needs: import java.util.AbstractList; import java.util.RandomAccess; The benefits are: avoid namespace collisions better readability, because you know the dependencies at a glance faster compilation Comments Variable Declaration private Node&...


6

Review I see no reason to have 3 constructors, each invoking the other, when two of them are private and only called by another constructor. Keep it simple. You check for if (Nodes == null) in the constructor. Is there a scenario where this reference could have already been created upfront? Constructor arguments should be camel cased. There is no point in ...


6

Here are my thoughts: Don't mutate function parameters unless there is good reason to do so. node.depth = level; The above statement basically breaks the contract of the function. The function claims to locate the deepestNode, but in fact it does findDeepestNodeAndSetDeepestPropOnAllNodes (silly, but you get the idea). This could lead to confusing, subtle ...


2

Use brackets for one-liner blocks (opinionated, but pretty strong consensus for this) Use shorthand object notation { val: val } -> { val } Use default value syntax Prefer const to let (this goes for your test too) Prefer ternary to if (not true if readability suffers) Let TreeNode take right and left as parameters module.exports = { deepestNode(node) { ...


2

Choosing the generic type (and parameters) The Fenwick tree stores cumulative values of its elements, and is based on the ability to compute the sum and difference of those elements. You made a very general implementation, where “sum” and “difference” are provided as closure parameters. But it cannot be ensured that these are proper inverse operations of ...


2

Specific suggestions: It is idiomatic to wrap the stuff after if __name__ == "__main__": in a main function. Rather than the generic data I would suggest figuring out exactly which information you want to attach to each Tree and creating fields for each of them rather than a fully generic list of stuff. This will make it much less painful to work with ...


1

Literature Since you never worked with a Tree structure before, I recommend reading about tree traversal strategies. Depth-First Breadth-First Order (bottom-up, top-down, in order) Bug Alert If you set the same value as is already set and the value is ITreeNodeAware<T>, it will end up with Node is null, while it should have the current instance set....


Top 50 recent answers are included