Best Answers

Finding K nearest distances

Problem Statement You are given millions of two dimensional point and a utility method to calculate their distances from the origin. Write a code to return the nearest K unique distances from the origin. If there are more than one point at the same distance, the distance must be just returned once. For e.g. If there are five points (1,1), (2,1), (1,2), (2,2) and (3,3) and the value of K is 3, then we need to return the following: 1.414 - distance of (1,1) from origin. 2.236 - distance of (2,1) or (1,2) from origin as both will be same. 2.828 - distance of (2,2) from origin Test ...
Read More

Find maximum element in array of alternate sequences

Problem Statement Given an array of elements which is first increasing and then decreasing, find maximum element in array of alternate sequences. Here is how an alternate sequence may look like : { 1, 3, 4, 7, 9, 6, 4, 2, 1 } Test Cases Here are few test scenarios which we must take into account before jumping into the code. input array is null input is empty array input has 1 element input has 2 element - increasing sequence. input has 2 element - decreasing sequence. input has N elements with proper increasing-decreasing sequence input has increasing sequence input...
Read More

Explain the Significance of Synchronized Keyword

Here is another favorite interview question for Java Interviews - Explain the significance of synchronized keyword. The wordings of the question may vary but the essence remain same. Before understanding synchronized keyword we must understand few things about Java's multi threading. Defining a Thread A thread is an Operating System concept. A process under execution is called a thread or we can also say that a thread is a light weight process. Now the Operating System may manage the processor in such a way that it appears that a processor can in parallel accomplish multiple tasks. Hen...
Read More

Explain Exception Handling in Java

This is one of the hottest Java Interview Questions for entry level and mid level software developers in Java. The question is mostly asked as "Explain Exception Handling in Java" but the wordings may change. Defining an Exception An exception indicates a problem that a reasonable application may wish to recover from. On a more formal note, "When a program violates the semantic constraints of the Java Programming Language, the JVM signals error to the program as an Exception. Many programming languages abruptly terminates programs in such scenarios but Java has a cleaner way of handling t...
Read More

What are the advantages of Java Programming Language?

The most basic question asked to a beginner in a Java Interview is "What are the advantages of Java Programming Language?". Here is a detailed answer to this question. Java is a relatively high level language. It provides lot of features out of the box, which makes it easy to learn for today’s developers and focus on the real business implementation rather than worrying about the system level infrastructure management. Few of the advantages of Java Programming Language are: Platform Independence : Java is platform independent, which means that if a program is written and compiled in Ja...
Read More