Java Interview Questions | Glassdoor

Java Interview Questions

6,004

interview questions shared by candidates

Java Interview Questions

Sort: RelevancePopular Date

Coderpad: given an array scores[][] = {“jerry”,”65”},{“bob”,”91”}, {“jerry”,”23”}, {“Eric”,”83”}} Find the student with highest average score

20 Answers

Given an array of integers where each element points to the index of the next element how would you detect if there is a cycle in this array?

18 Answers

1. Phone interview - Sort the characters in string by frequency and then by their alphabetical order. Example - bbaaccc -> cccaabb 2. The question that screwed me - given array is [0,1,1,0,1,1,1] ; output should be [0,1,1,0,1,2,3] ie., for every non-zero element in array, find its distance to the nearest zero in O(n) time. i would definitely encourage the candidates who read this post to share their solution for this question. 3. In order traversal of Binary search tree related (the solution is to start from right sub tree).

16 Answers

Given a list of n objects, write a function that outputs the minimum set of numbers that sum to at least K. FOLLOW UP: can you beat O(n ln n)?

15 Answers

Coding test: 1. Given a string, find out if there's repeat characters in it. 2. SQL. Given a Customer table and a Payment table (with Customer ID as primary and foreign key), write a query to output a list of customers who have not paid their bills in the last 3 months.

17 Answers

Given an array of integers, now we want to erase all 0's (can be other value), and we want the result array condensed, meaning no empty cell in the array.

16 Answers

Function to compute the number of ways to climb a flight of n steps. Taking 1, 2, or 3 steps at a time. Do it in Linear time and constant space. n = 3. 1 1 1 1 2 2 1 3 Ans = 4

15 Answers

You are trying to rob houses on a street. Each house has some +ve amount of cash. Your goal is to rob houses such that you maximize the total robbed amount. The constraint is once you rob a house you cannot rob a house adjascent to that house.

14 Answers

Find the first index of the substring. Condition: Do not use java library function or regular expressions. And measure the performance of your implementation with the standard java library function. Examples: String 1: “abcdefg” String 2: “bcd” Should return 1 String 1: “abcdefg” String 2: “x” Should return -1

14 Answers

class A { public A() { foo(); } public void foo() { System.out.println("Class A"); } } class B extends A { public B(){} public void foo() { System.out.println("Class B"); } } class main { public static void main(String[] args) { A a = new B(); } } What does it print? Class A or Class B?

13 Answers
1120 of 6,004 Interview Questions