Java Interview Questions
- 0of 0 votes
AnswersYou have an integer array. Starting from arr[startIndex], follow each element to the index it points to. You continue to do this until you find a cycle. Return the length of the cycle. If no cycle is found return -1
- rock January 26, 2021 in United States
forexample {1, 0}, 0) => 2
{1, 2, 0}, 0) => 3| Report Duplicate | Flag | PURGE
Goldman Sachs Senior Software Development Engineer Java - 0of 0 votes
AnswersIf ( a = True){
- 11gupt October 10, 2020 in United States
If (b = True){
Approve credit card;
}
Else {
Disapprove credit card;
}
}
Else {
If(C=False){
IF(D=True){
Approve Credit card;
}
else {
Diapprove credit card;
}
}
}
Simplify above written code.| Report Duplicate | Flag | PURGE
Data Engineer Java - 0of 0 votes
AnswersA Fibonacci sequence is defined recursively by:
- manojgct84 September 17, 2020 in India for Senior Software Engineer
F0 = 0
F1 = 1
Fn = Fn − 1 + Fn − 2, for integer n > 1.
One way of generalizing the Fibonacci sequence is by starting with any pair of numbers and extending to negative values of n.
Given two terms of a generalized Fibonacci sequence Fp and Fq, their positions p and q respectively and a position r, find Fr.
Input Format
The first line of the input contains an integer t denoting the number of test cases.
Each test case contains three lines.
First line of each test case contains two space separated integers p and Fp
Second line contains two space separated integers q and Fq
Third line contains an integer r
Output Format
For each test case, print Fr which is the term of the sequence at position r.
If Fr is not an integer, represent it as an irreducible fraction in the form a/b where b > 0.
Sample Input
0 1
6 13
10
3 65
6 315
-10
0 11
1 -6
2
9 36
15 646
-5
11 72
20 5473
6
Sample Output
89
4620
5
-1/4
13/2| Report Duplicate | Flag | PURGE
Sap Labs Senior Software Development Engineer Java - 0of 0 votes
AnswersJava:
- roxanadaniela35 April 10, 2020 in United States
Managing extreme sports locations:
In such locations, are period of the year when this actities can be performed(ski December - February, Kiting May August, ATV all year), each sport /location usually has an average cost/day.
The sports have hierarcal structure and countaind the country, region and city, we need an ADD, REMOVE, UPDATE; GET a location and all its informations.
exemple:
Switzerland:
Zurich:sky(dec, feb), price 12 $
Berna:ATV - all time , price 10$| Report Duplicate | Flag | PURGE
JDA Java Developer Java - -1of 1 vote
AnswersAs you know, most Operating Systems are written in Java, what’s special about pointers in Java ? *
- donk August 26, 2019 in United States for Engineering| Report Duplicate | Flag | PURGE
Notfamous Technical Support Engineer Java - 1of 1 vote
AnswersUse synchronized, wait() and notify() to write a program such that below mentioned conditions are fulfilled while reading and writing data to a shared resource.
- neer.1304 July 26, 2019 in United States
When a write is happening, no read or other write should be allowed(read and write threads should wait)
When a read is happening, no write should be allowed (write threads should wait) but. other read threads should be able to read.
Donot use any API classes e.g. ReadWriteLock, AtomicInteger etc..| Report Duplicate | Flag | PURGE
Microsoft SDE-2 Java - 1of 1 vote
AnswersShopping Cart Programming test.
- Vimal July 11, 2019 in India
There are multiple types of customer(Regular, Premium) they have been given a discount based on their purchase amount. for e.x
Premium Customer
1) 0-$5000 0%
2) $5000-$10000 10%
3) 10000 - above 20%
Regular Customer
1) 0-$4000 10%
2) $4000 - $8000 15%
3) $8000 - $12000 20%
4) $12000 - above 25%
Read input from console:
Input:
Regular
$5000
Output:
$5000
Input:
Premium
$7000
Output
$8000| Report Duplicate | Flag | PURGE
CDK Global Backend Developer Java - 1of 1 vote
AnswersYou have three Arrays.
- monowar1993 June 14, 2019 in Netherlands for Android
A = {2, 5, 3, 2, 8,1}
B = {7, 9, 5, 2, 4, 10, 10}
C = {6, 7, 5, 5, 3, 7}
make an array from this three arrays which elements is present in at least two array.
This question was followed by instead of three arrays. If you have a list of array then what will be the solution? Also what will be the time complexity?| Report Duplicate | Flag | PURGE
Booking.com Android Engineer Java - 0of 0 votes
AnswersA happy number is defined by the following process. Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers.
- sk2244 March 19, 2019 in India
Input:
Your program should read lines of text from standard input. Each line contains a single positive integer, N.
Output:
If the number is a happy number, print 1 to standard output. Otherwise, print 0.| Report Duplicate | Flag | PURGE
Sabre Holdings Java Developer Java - 0of 0 votes
AnswersYou have oracle database table , and AURORA AWS table with same fields , write a java lambda function to migrate data from oracle table to aurora. Also it should be realtime, if a new record is added to oracle it should update aurora db table as well.
- Brucewratner January 29, 2019 in United States| Report Duplicate | Flag | PURGE
Amazon Backend Developer Java - 0of 0 votes
AnswersMaximum Pairs
You are given N pencils. You have to make pairs of pencils.
The condition for making pairs is:
If(a,b) is any pair of pencils then b >= 2 * a. Here a and b are the sizes of pencils.
Now you have to find out the number of such pairs and the number of pencils which could not be paired with any pencils.
Note:
You need to pair the pencils in such a manner that the maximum number of pairs are formed.
Input Format:
The first line consists of number of test case T.
Each test case consist of:
- First line consists of a single integer N.
- Second line consists of N space-separated integers denoting the size of pencils Si.
Output Format:
For each test case, print two space-separated integers, first denoting the number of pairs formed and second denoting the number of unpaired pencils.
Answer for each test case should come in a new line.
Constraints
1<T<=10
1<=N<=10^5
0<=Si<=10^5
Sample Input
2
5
1 2 3 4 5
4
1 2 4 4
Sample Output
2 1
2 0
Explanation
In the first test case:-
we can form the following pairs:
(1, 3), (2, 4) and 5 remains unpaired hence maximum pairs are 2
In second test case:-
(1, 4), (2, 4) are two pairs hence no pencil left unpaired
- Karan Khosla January 04, 2019 in United States for 4public class Test { public static void main(String[] args) { } static int[] solve(int[] arr) { // the value at first index of array to be returned is number of pairs // formed and value at second index is unpaired swords. } }
| Report Duplicate | Flag | PURGE
Java Developer Java - 1of 1 vote
AnswersInt minSemsToFinishAllCourses(Map<string, list<string>)
Given a map containing courses and the list of prerequisites for that course in no particular order, determine the least number of semesters to finish all the courses.
- stevejabs November 22, 2018 in United States
You have to take all prerequisites before you take a given course.
Eg.
Calculus : English, math2
Math2: math 1, Arabic, english
Math1: english
English: <>
Arabic:<>
Give an algorithm for the above and code using java| Report Duplicate | Flag | PURGE
Algorithm Java - 0of 0 votes
AnswersGiven the arraylist<meals> input, find the number of dishes with unique ingredients.
class meals{ String cuisine; ArrayList<String> dish = new ArrayList<String>(); meals(String s, String[] arr){ cuisine = s; for(String i:arr){ dish.add(i); } } }
Example:
- venkataratnamkumar7777 September 18, 2018 in United States
Input: [
{
"cuisine" : "American",
"dish" : ["lettuce", "cheese", "olives", "tomato"]
},
{
"cuisine" : "Mexican",
"dish" : ["lettuce", "cheese", "pepper", "tomato"]
},
{
"cuisine" : "French",
"dish" : ["lettuce", "cheese", "pepper", "tomato"]
},
{
"cuisine" : "Continental",
"dish" : ["lettuce", "cheese", "olives", "tomato"]
},
]
Output: 2
Because there are two unique ingredient-dishes; {Mexican, French} and {American, Continental}.
I have tried different methods, but could not get to the solution. Thank you!| Report Duplicate | Flag | PURGE
Yelp Software Engineer Java - 0of 0 votes
Answersprint hockey stick number in pascal triangle where row of triangle can be upto 30000 and length of stick can be upto 100.
- Randhir September 09, 2018 in India| Report Duplicate | Flag | PURGE
Wissen Technology Software Developer Coding Data Structures Dynamic Programming Java - 0of 0 votes
AnswersTwo players and are playing a game.They are given binary numbers as input. Each binary number is represented as a string of characters '0' or '1'. The string always ends at '1'. In one move each player decides a bit position . Then he visits all the numbers and if their bit at that position is '1' then he changes it to '0'. It is mandatory to flip(change '1' to '0') bit of atleast one number in each move. The player who is unable to make a move loses. Player begins the game.
- fordosianDevil August 19, 2018 in United States
Input
First line contains a number as input. Next lines contain a binary string each.
Output
Print A if player A wins , B otherwise. In the next line print the move number of the last move of the winning player.| Report Duplicate | Flag | PURGE
Java - 0of 0 votes
AnswerI want to implement a simple HTTP Denial-of-Service protection. There are clients that can send HTTP request to a Server (i.e. a GET Method of http://10.1.1.2:8080/?clientId=7)
- Patrick July 18, 2018 in United States
if in an interval of 10 seconds more then 10 request comes from a specific client the 11th, 12th.. requests will get blocked. until 10 seconds from the first request will pass and then a new time windows of 10 seconds will be open. the idea is no more than 10 requests per 10 secs.
The time frame starts on each client’s first request and ends 10 seconds later.
I want to implement this logic on the server. Which data structures/collection/custom made object would you build to implement such a logic...
it is also important to have a threats safe solution.. and performances is also a factor here..
Thanks.| Report Duplicate | Flag | PURGE
Dropbox Software Trainee Java - 0of 0 votes
AnswersRound 3- Find the first duplicate occurence of a number in an array
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 3 - Write a java program to print a matrix in spiral
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 2 - Write a java program to determine if a 10 digit number is magic number.A number is magic number if it has all digits between 1 to 6 occuring in it or if it has any number between 0 to 9 occuring thrice or if it contains three consecutilvely increasing or decreasing digits differing by 1 example 345 or 543
- prashant.tah July 03, 2018 in India| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 2 - write java code to create the following pattern
- prashant.tah July 03, 2018 in India
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 1-question 1 - given an array of stock prices for n days.Write an algorithm to maximize the profit of a customer such that he can buy and sell only once.
- prashant.tah July 03, 2018 in India
-Question 2
Prove that complexity for searching in arraylist is o(n)
and adding is o(1)| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
Answerswrite java code to create the following pattern
- prashant.tah July 03, 2018 in India
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 0of 0 votes
AnswersRound 1-Question 1
- prashant.tah July 03, 2018 in India
1)Given an array of stock prices for 7 continuous days.Write an algorithm to maximize the profit for a customer who buys stock on any day and sells it later.Buying and selling can happen only once and selling should happen on any day after buying| Report Duplicate | Flag | PURGE
Oracle Senior Software Development Engineer Java - 2of 2 votes
AnswersI was asked to design a system on a whiteboard which simulate a executor.
- Patrick July 01, 2018 in United States
This system has a method that is being triggered every second. I need to add logic to the method (i.e. run jobs).
There is also a method called job_arrived() that is called when a new job arrives.. I need to implement it as well.
I needed to implement a system which tries to run each job right when it is arrived (it has a return value that gets a success status from a black box service). if the job ran successfully that's the end of it..
if not I need to re-run it after 2 seconds (and if that fails as well - there will be no re-runs).
of course - more than one job can be accepted each second.
I was asked to describes the system (describe the classes and method) and consider the system to be large scale one (meaning.. threading is in order here..).
The answer I gave was apparently not multi threaded enough..
any idea to what I should have done?
Thanks guys| Report Duplicate | Flag | PURGE
Facebook Software Developer Java - 0of 0 votes
Answershttps://codejamanalysis.wordpress.com/2017/03/18/crossover-problem-super-stack/
- akshaysjk June 13, 2018 in United States
Any Optimized Solution to avoid TLE for 4 test cases. I have tried by implementing Stack using Doubly Linked List.
Still not able to pass test cases!!!| Report Duplicate | Flag | PURGE
Java Developer Data Structures Java Stacks - 0of 0 votes
AnswersThere is a list of 20 words. 10 of them are good works, and 10 of them are bad words. Write a regex of not more than 25 characters which would tell if given word is good or bad. Input would only contain one of these 20 words.
- Ashish Dass June 02, 2018 in India
Good words: papa, book, home, cars, jolly, sugar, friend, mother, father, bloomiest
Bad words: ache, slow, torn, slum, boom, rival, wrong, cholera, revenge, arrogant
Input: book
Output: Good
Input: boom
Output: bad
Write Java Code using regex pattern| Report Duplicate | Flag | PURGE
Adobe Java - 0of 0 votes
Answers1. There is a list of 20 words. 10 of them are good works, and 10 of them are bad words. Write a regex of not more than 25 characters which would tell if given word is good or bad. Input would only contain one of these 20 words.
- Ashish Dass June 02, 2018 in India
Good words: papa, book, home, cars, jolly, sugar, friend, mother, father, bloomiest
Bad words: ache, slow, torn, slum, boom, rival, wrong, cholera, revenge, arrogant
Input: book
Output: Good
Input: boom
Output: bad| Report Duplicate | Flag | PURGE
Adobe Java Developer Java - 0of 0 votes
AnswersWhat is the issue with this Producer Consumer Problem. Can you fix it.
- dadakhalandhar May 26, 2018 in Indiapublic class ProducerConsumerProb { public static void main(String[] args) { Container container = new Container(); Turn turn = Turn.PRODUCER; Producer p = new Producer(container, turn); Consumer c = new Consumer(container, turn); Thread pro = new Thread(p); Thread con = new Thread(c); pro.start(); con.start(); } public static class Producer implements Runnable{ Container container; Turn turn; public Producer(Container integer,Turn turn) { this.container = integer; this.turn = turn; } @Override public void run() { for(int i=0;i<10;i++){ Turn temp = null; while(true){ synchronized (turn) { temp = turn; } if(temp == Turn.PRODUCER){ break; } } synchronized (turn) { container.setI(i); turn = Turn.CONSUMER; } } } } public static class Consumer implements Runnable{ Container container; Turn turn; public Consumer(Container integer,Turn turn) { this.container = integer; this.turn = turn; } @Override public void run() { for(int i=0;i<10;i++){ Turn temp = null; while(true){ synchronized (turn) { temp = turn; } if(temp == Turn.CONSUMER){ break; } } synchronized (turn) { System.out.println(container.getI()); turn = Turn.PRODUCER; } } } } public static class Container{ Integer i = new Integer(0); public int getI() { return i; } public void setI(int i) { this.i = i; } } enum Turn{ PRODUCER,CONSUMER; } }
| Report Duplicate | Flag | PURGE
Infinera Java Developer Java - 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
Open Chat in New Window