Data Scientist Intern Interview Questions in United States | Glassdoor.ca

Data Scientist Intern Interview Questions in United States

1

Data scientist intern interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Find the second largest element in a Binary Search Tree

16 Answers

find the right most element. If this is a right node with no children, return its parent. if this is not, return the largest element of its left child.

One addition is the situation where the tree has no right branch (root is largest). In this special case, it does not have a parent. So it's better to keep track of parent and current pointers, if different, the original method by the candidate works well, if the same (which means the root situation), find the largest of its left branch.

if (root == null || (!root.hasRightChild() ) { return null;} else return findSecondGreatest(root, root.getValue()); value findSecondGreatest(Node curr, value oldValue) { if(curr.hasRightChild()) { return (findSecondGreatest( curr.getRightChild(), curr.value)); } else return oldValue; }

See Interview Questions for Similar Jobs