Java Interview Questions
- 0of 0 votes
AnswersThere are hierarchy of class like super class and sub class. Yo have to make sure only one object can be create for any class using new keyword. How you implement the class.
- Randhir May 23, 2018 in United States| Report Duplicate | Flag | PURGE
Wissen Technology Java Developer Java - 0of 0 votes
Answersfind the sum of bit wise OR of minimum and Maximum element of all the subsets whose length is greater than 2 of the given of set.
- MukeshGupta0315 May 20, 2018 in India
for ex:-
{1,2,3} is set
then possible subsets of length is{ 1,2},{1,3},{2,3}{1,2,3} answer 1|2 +1|3 +2|3 +1|3=12| Report Duplicate | Flag | PURGE
Samsung Software Engineer Java - 1of 1 vote
AnswersLet’s say you have two input arrays with sorted elements. Find the union.
- prasad.hybris May 16, 2018 in United States
a[] = {2, 10, 14, 19, 51, 71}
b[] = {2, 9, 19, 40, 51}
Union = {2, 9, 10, 14, 19, 40, 51}| Report Duplicate | Flag | PURGE
Amazon SDE1 Java - 0of 0 votes
Answerwhy we have a such long number value for object's hashcode in java.can we not have any small numbers or why java is giving that much large number for any object hash code ?
- Vikas271572 May 15, 2018 in United States| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersList<Integer> list=Arrays.asList(1,2,3,4,5,6);
- Randhir May 14, 2018 in India
Iterator it=list.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
The above code will iterate sequentially through 1 to 6. Can we iterate the same list alternatively so that it will print 1,3,5 without changing the while loop.| Report Duplicate | Flag | PURGE
Wissen Technology Java Developer Java - 1of 1 vote
AnswersGiven a number, rearrange the digits of that number to make a higher number, among all such permutations that are greater,one of them is the smallest, Find the smallest greater permutation (the next Permutation).
- sarunreddy82 May 13, 2018 in United States
Examples:
next_permutation (12) = 21
next_permutation (315) = 351
next_permutation (583) = 835
next_permutation (12389) = 12398
next_permutation (34722641) = 34724126| Report Duplicate | Flag | PURGE
Facebook Java - 0of 0 votes
AnswersProblem:
- sarunreddy82 April 29, 2018 in United States
Insert + or – sign anywhere between the digits 123456789 in such a way that the expression evaluates to 100. The condition is that the order of the digits must not be changed.
e.g.: 1 + 2 + 3 – 4 + 5 + 6 + 78 + 9 = 100
I have below C solution - Can you please help me to convert to Java. I need this solution in Java.
#include<stdio.h>
#include<conio.h>
int findnumber(int i,int j)
{
int k;
int n;
for(k = 0; k < j; k++)
{
n = i % 3;
i = i / 3;
}
return n;
}
void main()
{
int i, j, k, current, result, operation;
clrscr();
for(i = 0; i < 19683; i++)
{
if(i%3 == 0)
continue;
current = 0;
result = 0;
for(j = 1; j < 10; j++)
{
k = findnumber(i,j);
if(k==0)
{
current = current * 10 + j;
}
else
{
result = result + (operation == 1 ? current : -current);
current = j;
operation = k;
}
}
result = result + (operation == 1 ? current : -current);
if(result == 100)
{
for(j = 1; j < 10; j++)
{
k = findnumber(i,j);
if(k==0)
printf("%d",j);
else
printf("%c%d",k==1?'+':'-',j);
}
printf("\n");
}
}
getch();
}| Report Duplicate | Flag | PURGE
xyz Java - 0of 0 votes
AnswersNeed to design and develop java program for assigning rankings to “Premier League” players. To start with all the players would have zero points. After every game, points would be updated for players based on the performance. Design data structure and algorithm to print the player rankings after every game.
- deepakSU April 18, 2018 in United States
Sample input and outputs:
Input to program would be of the format “player Id, points from the game”. Example :
1 2
2 1
3 5
1 2
2 3
3 5| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
Answers### Problem 3: Theatre Seating
- harshshukla54 April 15, 2018 in United States
You run a small theater and each month, you have patrons mail in requests for pre-sale tickets. You need to process these ticket requests and either tell them where their party will sit or explain to the patron why you can't complete their order.
You have a few rules that you need to follow when you fill the orders:
1. Fill as many orders as possible
2. Put parties as close to the front as possible.
3. If there are not enough seats available in the theater to handle a party, tell them "Sorry, we can't handle your party."
4. Each party must sit in a single row in a single section. If they won't fit, tell them "Call to split party".
Your program must parse a theater layout and a list of ticket requests and produce a list of tickets or explanations in the same order as the requests.
The theater layout is made up of 1 or more rows. Each row is made up of 1 or more sections separated by a space.
After the theater layout, there is one empty line, followed by 1 or more theater requests. The theater request is made up of a name followed by a space and the number of requested tickets.
Sample input:
```
6 6
3 5 5 3
4 6 6 4
2 8 8 2
6 6
Smith 2
Jones 5
Davis 6
Wilson 100
Johnson 3
Williams 4
Brown 8
Miller 12
```
Your program must produce results to standard output in the same order as the requests, with the name of the person who requested the ticket and either the row and section of the ticket or the explanations "Sorry, we can't handle your party" or "Call to split party."
Sample output:
```
Smith Row 1 Section 1
Jones Row 2 Section 2
Davis Row 1 Section 2
Wilson Sorry, we can't handle your party.
Johnson Row 2 Section 1
Williams Row 1 Section 1
Brown Row 4 Section 2
Miller Call to split party.| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersWrite a program that controls the traffic signals for a four-way intersection. Initially, we consider traffic flowing in straight lines only, no turns. The four directions are S(outhbound) and N(orthbound) on Snell Rd; and W(estbound) and E(astbound) on Weaver Rd. The traffic lights should obey the following rules:
- harshshukla54 April 15, 2018 in United States
1. Cars arrive in each direction on both roads (Snell and Weaver) at the rate of 1 car per second. That is, 4 cars approach the intersection each second.
2. Only one road (Snell or Weaver) can have a "green" light at one time.
3. It is acceptable for both roads to have the "red" light at the same time. Of course, traffic backs up on both roads if this happens.
4. Start by turning on the traffic on Snell Rd "green" in both directions for 3 seconds; then turn it "red" for one second; then turn Weaver "green" for 3 seconds; and then red for one second.
5. When the light turns from red to green at any intersection, it takes the first car 2 seconds to start moving and cross the intersection. Subsequent cars take 1 second each.
6. At the instant the light turns from "green" to "red", a car may not start moving to cross the intersection; whether that car just arrived at the intersection or was waiting at that intersection.
7. The output should be the number of cars that are waiting at the intersection in each direction at each second, for the first 20 seconds. Do not make the program wait 20 seconds to produce the output: this is only a simulation, so print the output when it's ready.
8. Expected output
```
0: N = 0; S = 0; E = 0; W = 0
1: N = 0; S = 0; E = 1; W = 1
2: N = 0; S = 0; E = 2; W = 2
3: N = 0; S = 0; E = 3; W = 3
4: N = 1; S = 1; E = 4; W = 4
5: N = 2; S = 2; E = 5; W = 5
6: N = 3; S = 3; E = 5; W = 5
7: N = 4; S = 4; E = 5; W = 5
8: N = 5; S = 5; E = 6; W = 6
```| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersDenver International Airport has decided to give an automated baggage system another shot. The hardware and tracking systems from the previous attempt are still in place, they just need a system to route the baggage. The system will route baggage checked, connecting, and terminating in Denver.
- harshshukla54 April 15, 2018 in United States
You have been asked to implement a system that will route bags to their flights or the proper baggage claim. The input describes the airport conveyor system, the departing flights, and the bags to be routed. The output is the optimal routing to get bags to their destinations. Bags with a flight id of “ARRIVAL” are terminating in Denver are routed to Baggage Claim.
Input: The input consists of several sections. The beginning of each section is marked by a line starting: “# Section:” ``` Section 1: A weighted bi-directional graph describing the conveyor system. Format: <Node 1> <Node 2> <travel_time>
Section 2: Departure list Format: <flightid> <flightgate> <destination> <flighttime> Section 3: Bag list Format: <bagnumber> <entrypoint> <flightid> ```
Output: The optimized route for each bag `
The output should be in the same order as the Bag list section of the input.
Example Input: ```
Section: Conveyor System
ConcourseATicketing A5 5 A5 BaggageClaim 5 A5 A10 4 A5 A1 6 A1 A2 1 A2 A3 1 A3 A4 1 A10 A9 1 A9 A8 1 A8 A7 1 A7 A6 1
Section: Departures
UA10 A1 MIA 08:00 UA11 A1 LAX 09:00 UA12 A1 JFK 09:45 UA13 A2 JFK 08:30 UA14 A2 JFK 09:45 UA15 A2 JFK 10:00 UA16 A3 JFK 09:00 UA17 A4 MHT 09:15 UA18 A5 LAX 10:15
Section: Bags
0001 ConcourseATicketing UA12 0002 A5 UA17 0003 A2 UA10 0004 A8 UA18 0005 A7 ARRIVAL ```
Example Output: `
0001 Concourse_A_Ticketing A5 A1 : 11 0002 A5 A1 A2 A3 A4 : 9 0003 A2 A1 : 1 0004 A8 A9 A10 A5 : 6 0005 A7 A8 A9 A10 A5 BaggageClaim : 12| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswersGiven an array of n elements return true if 3 of the sum of 3 elements is equal to a constant c
- mapardotl April 10, 2018 in United States for Facebook groups
Example array a[6,2,3,4] constant c = 9
if a[1] + [2] + [3] == c return true
The size of the array is n
If any set of 3 elements is equal to the constant c, then return false| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Java - 0of 0 votes
AnswerLongest increasing subsequence, Number of Island, Basic SQL questions like joins, select statement etc, Code for finding the Name in the document. Like based on the property of name (which cannot be written in small case). Find its frequency.
- Aspiring_coder March 29, 2018 in United States| Report Duplicate | Flag | PURGE
Zulily SDE-2 Java - 0of 0 votes
AnswersA number of islands. All the rounds had basic DB questions
- Aspiring_coder March 29, 2018 in United States| Report Duplicate | Flag | PURGE
Zulily SDE-2 Java - 0of 0 votes
AnswersNumber of islands. Big(O).
- Aspiring_coder March 29, 2018 in United States| Report Duplicate | Flag | PURGE
Zulily SDE-2 Java - 0of 0 votes
AnswersIn the doc file the "Name" without any dictionary. Like finding the property of the name as Starts with the capital letter. Then find the frequency of only names present in the doc. Whiteboard coding
- Aspiring_coder March 29, 2018 in United States| Report Duplicate | Flag | PURGE
Zulily SDE-2 Java - 0of 0 votes
AnswerLongest Increasing Subsequence
- Aspiring_coder March 29, 2018 in United States| Report Duplicate | Flag | PURGE
Zulily SDE-2 Java - 0of 0 votes
AnswersGiven: Collection of sorted (ascending) iterators which return integer value.
Implement hasNext() and next() methods in SuperIterator class that next() method should return sorted values from all iterators.
Note that we can't load all iterators to memory, because they might get values from big file (1TB for instance) and it will lead to OutOfMemoryError.
- mhenro March 21, 2018 in United States/* iter1: 1, 4, 5, 20, ... iter2: 2, 10, 12, 50, ... SuperIterator.next() method should return: 1, 2, 4, 5, 10, 12, 20, 50, ... */ interface Iterator { boolean hasNext(); int next(); } class SuperIterator { public SuperIterator(Collection<Iterator> iters) { } boolean hasNext() { //TODO } int next() { //TODO } }
| Report Duplicate | Flag | PURGE
Java Developer Java - 0of 0 votes
AnswersGiven a string "L*&EVe)))l", write a method which will determine if the input is a palindrome. Ignore all special characters. Uppercase/lowercase should be considered as same.
- androidenthusiast March 12, 2018 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Java - 0of 0 votes
AnswersImagine a room full of people, with only 1 celebrity in the room. Celebrity is defined as a person who does not know anyone, but everyone knows him/her. Write a method who will take array of people and a person as input and return boolean if the person is a celebrity or not.
- androidenthusiast March 12, 2018 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Java - 0of 0 votes
AnswersFind the missing letters from a string if it doesn't create a pangram.
- lord.claxton March 08, 2018 in United States| Report Duplicate | Flag | PURGE
JP Morgan Associate Java - 0of 0 votes
Answershttps://leetcode.com/problems/word-search/description/
- lord.claxton March 08, 2018 in United States
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
For example,
Given board =
[
['A','B','C','E'],
['S','F','C','S'],
['A','D','E','E']
]
word = "ABCCED", -> returns true,
word = "SEE", -> returns true,
word = "ABCB", -> returns false.| Report Duplicate | Flag | PURGE
JP Morgan Associate Java - 0of 0 votes
AnswersGiven a Binary string of 0s and 1s, and k, Find the number of different ways to get longest continuous streak of 1s. You can flip any k number of 0s to 1s.
- delta_x February 12, 2018 in India
Example:
1)Stirng is S=1010101, K=1
Result=3
1)Stirng is S=01010, K=3
Result=1| Report Duplicate | Flag | PURGE
Lava Front-end Software Engineer Java - 0of 0 votes
AnswersGiven list of strings like “ crane, drain, refrain” and a pattern such as *an*
- tushr1388 February 05, 2018 in United States
where * can match any number of chracters.
Return the matching word in an efficient manner.
Answer to above question : crane| Report Duplicate | Flag | PURGE
Facebook SDE1 Java - 0of 0 votes
Answerdesign a zigzag iterator, implement the prev() and hasPrev function
- shuibizai10 December 26, 2017 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Java - 1of 1 vote
AnswersWrite a program to return nearest elements from a binary search tree for input element.
- mh4wt@virginia.edu December 23, 2017 in United States| Report Duplicate | Flag | PURGE
Amazon Intern Java - 0of 0 votes
AnswersThere is a dictionary already implemented. Write a method , which takes input String without space, to replace the characters from the strings which are not present in dictionary with –
- mh4wt@virginia.edu December 23, 2017 in United States
Example: Dictionary – a*
………….Input- aaabaa
………….Output- aaa_aa| Report Duplicate | Flag | PURGE
Amazon Intern Java - 0of 0 votes
AnswersThere is a dictionary already implemented. Write a method, which takes input String without space, to prints all subsets of the input string which is present in dictionary.
- mh4wt@virginia.edu December 23, 2017 in United States
Example: Dictionary – a*
………….Input- aaabaa
………….Output- a,a,a,aa,aa,aaa,a,a,aa| Report Duplicate | Flag | PURGE
Amazon Intern Java - 2of 2 votes
AnswersGiven two sorted linked lists, how can you combine them into one big sorted list? Do not create additional nodes.
- kredible November 12, 2017 in Singapore| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java - 0of 0 votes
AnswersThere is going to be a sale during this month. You are interested in a particular item and you found that different Vendors have different prices during different time periods. You collected the following information:
Vendor => (start date, end date, price) both sides inclusive A => (1, 5, $20) B => (3, 6, $15) C => (2, 8, $25) D => (7, 12, $18) E => (1, 31, $22)
As you can see, there are conflicting entries. You need to print out a non-conflicting schedule of prices, taking the best price from each period:
- kredible November 12, 2017 in Singapore
e.g.
(1, 2, $20), (3, 6, $15), (7, 12, $18), (13, 31, $22)| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java
Open Chat in New Window