Java Interview Questions | Glassdoor

Java Interview Questions

5,972

interview questions shared by candidates

Java 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; }

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

What is an abstract class and why would you use it?

2 Answers

Write a method to determine if a string starts with an uppercase letter.

2 Answers

What is a volatile variable, and why would you use it?

2 Answers

1.Java Basics. 2.Plethora of Multithreading questions.GC 3.Simple data structure. (BFS) variation 4.Database Basics

1 Answer

Q: Why multiple inheritances are not supported in Java?

1 Answer

What is the most used Java class?

1 Answer

In a Unix environment what are the top 3-5 considerations for performance monitoring a Java application that has access to a local Oracle instance (located on the same server). Please be as specific as possible (i.e. commands, locations, etc.)

1 Answer

Explain the development process of a previous project.

1 Answer

Difference between JDBC and Hibernate

1 Answer
110 of 5,972 Interview Questions