int (@Nullable Node<T> node, int offset, int deltaUpToRootExclusive) { if (node == null) return 0; int delta = deltaUpToRootExclusive + node.delta; if (offset >= node.maxEnd + delta) return node.subtreeSum; int value = getSumOfValuesForOverlappingRanges(node.getLeft(), offset, delta); if (offset >= node.intervalStart() + delta) { value += node.getLocalSum(); value += getSumOfValuesForOverlappingRanges(node.getRight(), offset, delta); } return value; }