Tripadvisor Interview Question

Write code for a binary tree who find the lowest node and bubbles it up to the root.

Interview Answers

Anonymous

Jul 24, 2014

what do you mean by bubble up!?

3

Anonymous

Apr 18, 2015

private static Node root; private static Node temp; private static int least = Integer.MAX_VALUE; private static Node swapLeast(Node r) { if (r.val < least) { least = r.val; temp = r; } if (r.left != null) swapLeast(r.left); if (r.right != null) swapLeast(r.right); temp.val = root.val; root.val = least; return root; }