First Mock with Laoliu
Behavior Question
introduce yourself
current work? answer yes, and then answer why leave bq and why amazon
conflict with manager
miss deadline( could also be challenge project)
do you know binary tree?
yes, binary tree has at most two node, left or right or null;
why use list?
we could change the length of the list, but we can't always change arrays' length;
Give you a binary tree, return the node which are always at right;
public <List<List<TreeNode>> levelOrder(TreeNode root){
List<List<TreeNode>> res = new ArrayList<>();
if(root == null) return res;
Queue<TreeNode> queue = new LinkedList<>();
queue.offer(root);
while(!queue.isEmpty()){
int size = queue.size;
List<TreeNode> list = new ArrayList<>();
for(int i = 0; i < size; i++){
TreeNode node = queue.poll();
if(node.left != null) queue.offer(node.left);
if(node.right != null) queue.offer(node.right);
if(i == size - 1) list.add(node.val);
}
res.add(list);
}
return res;
}
Last updated
Was this helpful?