Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

Hidden Document
Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content Hidden Document Content

.....

.....

.....

Like the course? Get enrolled and start learning!
Tobby Lie

Tobby Lie

· 2 years ago

This might not be super important but I thought adding a success flag that gets returned by each query call might be useful to determine if you need to decrement internal nodes after returning recursive calls. Reason being, in the case where a leaf node is not decremented, you wouldn't want to naively decrement internal nodes when returning up the recursion stack.

@staticmethod def query(segmentTree, resultQueue, index, left, right, position, height, originalPosition): # If segment can't accommodate the position, fail early if segmentTree[index] < position: return False # If it's a leaf node if left == right: resultQueue[left] = [height, originalPosition] segmentTree[index] -= 1 return True # Successfully placed mid = left +

Reading Progress

0%