@jeantimex "Also, I am curious how you are going to "maintain" the window of size k using what data structure (array, deque, priority queue or something else)" - Just an idea, can we simply do a traversal of othe tree (no matter it's inorder or preorder or postorder), and maintain a max-heap of size K, which stores the K nodes values that are closest to the target. This takes O(N), and space is O(K). And this seems has nothing to do with BST, for any BT we can do this. So I kind of agree with other people's opinions that there should be a better algorithm than O(N) as this is BST.
Posts made by Zhuzeng
RE: AC clean Java solution using two stacks
RE: 36 ms C++ solution
@StefanPochmann But you do modify it in the code
grid[i][j]--;, right? But I also see that your function looks like:
shortestDistance(vector<vector<int>> grid), which is not the same as the OJ provides
shortestDistance(vector<vector<int>>& grid). So did you choose to modify the function prototype? I know it's totally OK to do so as the OJ has no idea about this, but just trying to understand the whole story.
Why "++++-++++++" is a TRUE?
Can anyone please confirm why the expected result for the following test case is TRUE?
My code failed because my alg is giving 'false', but I am a little confused why the OJ gives 'TRUE'. No matter what the first player does, the second player can find a way to eventually win the game. Am I missing some critical info here?