Java Interview Questions
- 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 - 2of 2 votes
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 - 3of 5 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 - 1of 1 vote
AnswersGiven a list of currency exchange rates like this:
EUR/USD => 1.2
USD/GBP => 0.75
GBP/AUD => 1.7
AUD/JPY => 90
GBP/JPY => 150
JPY/INR => 0.6
write a methoddouble convert(String sourceCurrency, double amount, String destCurrency);
For example, convert(EUR, 100, INR)
- kredible November 12, 2017 in Singapore
The method should minimize the number of intermediate conversions.| Report Duplicate | Flag | PURGE
Goldman Sachs Software Engineer / Developer Java - 1of 1 vote
AnswersGiven a Map (representing an old phone key number and possible letters present there) and a sequence of keys return all possible combinations of strings that are possible to produce.
Map<String, String[]> map = new HashMap<String, String[]>(); map.put("1", new String[] { "a", "b", "c" }); map.put("2", new String[] { "c", "d", "e" }); map.put("3", new String[] { "f", "g", "h" }); String in = "12"; List<String> mix(String in, Map<String, String[]> map)
The result for "1,2" should be [ac, bc, cc, ad, bd, cd, ae, be, ce]
- Bruno November 09, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Java - 0of 0 votes
AnswersWrite all the possible numbers returned from a calculator pad where a start number move in a L direction in any directions(1-2moves)
- wingchuihk November 08, 2017 in United States
ie. From calculator pad. Start from 8 --> go in L shape (2up, 1right), and it returns 3
ie. Start from 2, (move 2 down, 1 left), it will be 7
ie. Start from 2(move 2 down, 1 right), it will be 9
ie. Start from 7(move 1 left, 2 up), it will be 2
ie. Start from 7(move 1 up, 2 left), it will be 6| Report Duplicate | Flag | PURGE
Google SDET Java - 9of 9 votes
AnswersDeveloping Java game
- stallapp November 03, 2017 in United States
creating a RESTful service using which players can play a simple game described
below.
The game should have the following rules:
• The player has an infinite amount of coins.
• The player bets 10 coins to play a normal game round.
• In any round (free or normal), the player has a 30% chance of winning back 20 coins.
• In any round (free or normal), the player also has a 10% chance of triggering a free round where
the player does not have to pay for bet. The free round works in the same way as a normal round except
it costs 0 coins. The free round should follow immediately after the normal round.
• The player can both win coins and free round at the same time.| Report Duplicate | Flag | PURGE
Amazon Backend Developer Java - 1of 1 vote
AnswersTesting Strings
- pooja.senger86 October 29, 2017 in United States
Mr X and Mr Y, his friend are programmers and testers respectively working in the same company. So, once they faced the following scenario :
Mr X wrote an application that took as input some user data. The data the application took as input was a string in some strange language. That language consisted of
K
K distinct letters. However, due to some issues, the application got corrupted and one particular String among many was lost.
However, Mr X had seen that String once before it got lost. He remembers some info about it. Particu-larly, he remembers the lost String had length equal to
M
M.
Mr Y, being the chief QA person in his company needs to try and figure out the number of possible different possible candidate Strings for the lost String.
Mr X remembers N pieces of info. For each one, he gives you 2 numbers
L
L and
R
R and a number
Z
Z. He remembers for sure that the
Z
t
h
Zth letter of the language of the string did not occur between positions
L
L and
R
R inclusive of the lost String.
Input Format :
The first line contains
3
3 space separated integers
N
N ,
M
M and
K
K.
Each of the next
N
N contains
3
3 space separated integers, denoting
L
L ,
R
R and
Z
Z respectively.
Output Format :
You need to find and print the number of different possible candidate Strings for the lost String based on the info Mr X remembers. As the number of such Strings can be large, print it Modulo
10
6
+
3
106+3
Constraints:
1
≤
N
,
M
,
K
≤
10
5
1≤N,M,K≤105
1
≤
L
≤
R
≤
M
1≤L≤R≤M
1
≤
Z
≤
K
1≤Z≤K
Sample Input
1 2 26
1 2 1
Sample Output
625| Report Duplicate | Flag | PURGE
A9 abc .Net/C Java - 0of 0 votes
AnswerToday Jin has given a task to Shino, Shino has to travel from cell
- pooja.senger86 October 29, 2017 in United States
(
1
,
1
)
(1,1) to cell
(
N
,
M
)
(N,M) in a grid of size
N
∗
M
N∗M. But in order make this task interesting for Shino, Jin has decided to keep some special candies in some
K
K special cells of the grid, where each candy has an amount of happiness associated with it.
Shino can travel only in right & down direction in the grid, as he is too careful & does not want to fall out of grid. Now, we call the value of a path the happiness of all cells lying on the path. All non-special cells have happiness equal to
0
0.
Now, you need to find and print the sum of the values of all paths from
(
1
,
1
)
(1,1) to
(
N
,
M
)
(N,M), traveling only right and down to an adjacent cell.
As Shino is not good at counting help him find the answer.
Input Format
The first Line contains a single integer
T
T denoting number of test cases
The next line contains
3
3 space separated integers,
N
N,
M
M and
K
K where N * M is the size of grid & K denoting number of special cells
The next
K
K lines contains three integers
X
i
,
Y
i
,
H
i
Xi,Yi,Hi where
(
X
i
,
Y
i
)
(Xi,Yi) is cell coordinate &
H
i
Hi is the amount of happiness Shino will get from a candy at cell
(
X
i
,
Y
i
)
(Xi,Yi)
Constraints
1
≤
T
≤
3
1≤T≤3
1
≤
N
,
M
,
K
≤
10
5
1≤N,M,K≤105
1
≤
X
i
≤
N
,
1
≤
Y
i
≤
M
1≤Xi≤N,1≤Yi≤M
1
≤
H
i
≤
10
5
1≤Hi≤105
Output Format
For each test case you will output a single integer denoting the total amount of happiness Shino will get. As the answer can be quiet large you can output answer modulo
10
9
+
7
109+7
Sample Input
1
2 2 2
1 2 4
2 1 7
Sample Output
11| Report Duplicate | Flag | PURGE
A9 abc .Net/C Algorithm Java - -6of 6 votes
AnswerFolders and Cows Hackerrank Dropbox Question.
- John October 02, 2017 in United States
I haven't opened the link, so I don't know the prompt and I have only have 75mins to complete it starting when I begin the challenge.| Report Duplicate | Flag | PURGE
Java - 2of 2 votes
AnswersPrint Common Suffix In Strings
- praveenz.poola September 15, 2017 in India
Ex: cornfiled , Exfiled --- field| Report Duplicate | Flag | PURGE
Cisco Systems Software Engineer Java - 7of 7 votes
AnswerWrite a method called createArray that accepts 4 parameters: number of rows, number of columns, a and b.
- mimiaarabi August 05, 2017 in United States
This method creates a 2-D array of number rows and columns as given in the parameter, then fills the array
with random values between a and b.
Write another method called checkColumn which accepts the position of the column, the min and max
elements of the array as parameter and returns true if the column contains both the minimum value and
maximum value, false otherwise.
Finding the min and max can be done in the main.
Sample run:
Enter number of rows and columns: 3 2
Enter 2 integers: 25 40
Array Elements:
26 32
39 28
27 30
Minimum: 26 Maximum: 39
Enter the position of the column to check: 0
Column 0 contains both min and max.| Report Duplicate | Flag | PURGE
Internet Question Java - 0of 0 votes
AnswerWe need to develop a game that allows two players to throw a dice ten times and the player who gets the
- mimiaarabi August 05, 2017 in United States
highest sum wins the game.
Write a method sum(int[] values) that returns the sum of elements of the array values.
Write a method display(int[] values) that displays the elements of the array values.
Write a main method where you should:
a) Create two arrays of integers called player1 and player2 with size 10 both
b) For each player, generate ten random integers between 1 and 6 inclusively. The generated values
are added to the associated array of each player.
c) Display the generated values for each player.
d) Find and display the winner using the sum method.
Sample run
Generated numbers for player 1 are: 6 6 3 1 2 1 4 6 5 4
Generated numbers for player 2 are: 6 2 2 4 2 1 1 5 2 4
Player 1 wins with score 38| Report Duplicate | Flag | PURGE
Internet Question Java - 0of 0 votes
Answer[Applying a curve to grades] Write a method called “applyCurve” that takes as a parameter a single-
- mimiaarabi August 05, 2017 in United States
dimensional array called “grades” of integers and a single value integer called “raise”. This method should
modify the array “grades“, which contains the grades of students in a way that each value in the array is
added to it the curve value “raise”. You should check that the grades after applying the raise does not exceed
100.
For example, if array “grades” contains the following values:
95 100 24 43 76 51 87
0 1 2 3 4 5 6
After calling the method “applyCurve” with a raise value +7 the array grades would be as follows:
100 100 31 50 83 58 94
0 1 2 3 4 5 6
Write a test program (main) that prompts the user to enter the size of an array, the grades and the required
curve and then displays the grades after applying a required curve.
Sample run
Enter the array size: 7
Enter the grades: 95 100 24 43 76 51 87
Enter the required curve: 7
The grades after applying + 7 are: 100 100 31 50 83 58 94| Report Duplicate | Flag | PURGE
Internet Question Java - 0of 0 votes
AnswersFor given list of numbers find out triplets with sum 0
- rsa July 14, 2017 in United States
Input : arr[] = {0, -1, 2, -3, 1}
Output : 0 -1 1
2 -3 1| Report Duplicate | Flag | PURGE
Facebook Java - 1of 1 vote
AnswersGiven a String and dictionary of words, break the string in minimum space sentence.
- rsa July 14, 2017 in United States
Ex:
inputStr = "ilikefacebook"
dictionary = {"i","like","face","book","facebook"}
Possible Strings:
i like face book - 3 spaces
i like Facebook - 2 spaces - this is expected answer.| Report Duplicate | Flag | PURGE
Facebook Java - 0of 0 votes
AnswersHow do you reverse the words in a linked list?
For ex, Convert " H-e-l-l-o- -W-o-r-l-d " (There is a space between the word), into " o-l-l-e-H- -d-l-r-o-W "
Write a Java code to use as less Space Complexity as possible. (So not too many spaces should be used)
Linked List Structure:
- sambenison66 July 04, 2017 in United Statesclass Node { char val; Node next; }
| Report Duplicate | Flag | PURGE
Google Software Engineer in Test Java - 0of 0 votes
AnswersWrite a custom implementation of BlockingQueue using only intrinsic locking constructs in Java
- Flash May 14, 2017 in India| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersWrite a program to generate the anagrams of a word
- Flash May 14, 2017 in India| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersWrite a program to reverse a string
- Flash May 14, 2017 in India| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersWhat is the output of following code snippet?
- Flash May 14, 2017 in Indiapublic static void main(String[] args){ int[][] data = {{123},{4,5,6}}; int[][] copy = data.clone(); copy[0][0] = 100; System.out.println(data[0][0]); System.out.println(copy[0][0]); copy[1] = new int[]{300,400,500}; System.out.println(data[1][1]); System.out.println(copy[1][1]); }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersWhat would be the output of below code snippet?
- Flash May 14, 2017 in Indiaclass Super { int index = 5; public void printVal(){System.out.println("Super");} } class Sub extends Super { int index = 2; public void printVal(){System.out.println("Sub");} } public class OopTest { public static void main(String[] args){ Super sup = new Sub(); System.out.println(sup.index + " "); sup.printVal(); } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersGiven a binary tree of integers, write code to store the tree into a list of integers and recreate the original tree from a list of integers.
- Null0 May 13, 2017
Here's what your method signatures should look like (in Java):
List<Integer> store(Node root)
Node restore(List<Integer> list)
Example Tree:
5
/ \
3 2
/ / \
1 6 1| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm Data Structures Java Trees and Graphs - 0of 0 votes
AnswersWhat would be the result of executing the below code snippet?
- Flash May 13, 2017 in Indiapublic class CountDownLatchDemo { public static void main(String[] args)throws InterruptedException { final CountDownLatch latch = new CountDownLatch(3); latch.countDown(); latch.countDown(); new Thread(){ public void run(){ try{ Thread.sleep(3000); }catch(InterruptedException ex){ ex.printStackTrace(); } latch.countDown(); }; }.start(); System.out.println("Before"); latch.await(); System.out.println("After"); } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java