Amazon Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
I dont remember properly but i'm sure it was just BFS implementaion and also asked me
Which datastructure u use to keep track of visited nodes..? ans: HashMap
static void bfs(BinaryTreeNode node) {
- pdhingra December 27, 2012Queue<BinaryTreeNode> queue = new LinkedList<BinaryTreeNode>();
queue.add(node);
while (!queue.isEmpty()) {
BinaryTreeNode tmp = queue.poll();
System.out.println(tmp.data.getSsn() + "~" + tmp.data.getName());
if (tmp.left != null) { queue.add(tmp.left);}
if (tmp.right != null) { queue.add(tmp.right);}
}
}