Java Developer Interview Questions
- -1of 3 votes
Answerspublic string stringWrap (String text, int characters)
text is an input string, characters on behalf of the output of
each line up to the number of bytes
input
- ajay.raj January 30, 2018 in United States"Thank you for shopping at the XYZ store.\n Your order has been processed successfully.\n", 20 output: "Thank you for\n shopping at the XYZ\n store.\n Your order has been\n processed\n Successfully.\n" example 2:"Hello! How are you?",6 output “Hello!\n How\n are\n you?\n"
| Report Duplicate | Flag | PURGE
Google Java Developer - -2of 2 votes
AnswerImagine a scenario where there are N cars on an infinitely long single-lane road. Each car has a unique, permanent integer speed ranging between 1 and N, inclusive (units are irrelevant). The cars can be placed in any order along the road and then told to start driving indefinitely. Let's assume that the cars are traveling from right-to-left. So the leftmost car is at the front. Given an ordering of N cars, construct an algorithm to return an array of cluster sizes
- ajay.raj January 26, 2018 in United States
N=4
[2, 4, 1, 3] -> [2, 2]
[2, 5, 4, 3, 1] -> [4, 1]
followup:
New car speed = N+1. Given an ordering of N cars, construct an algorithm to return an array of arrays of cluster sizes that will arise when the N+1 car is inserted. The ith row in the outer array corresponds to the cluster sizes that exist when the N+1 car is inserted into the ith index
new car speed = 5
[2, 4, 1, 3] -> [[1, 2, 2], [3, 2], [3, 2], [2, 3], [2, 3]]| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersGiven a string as a datastream Iterator<Character>, find the length of the longest substring without repeating characters
- ajay.raj January 18, 2018 in United States
public String longestUniqueChars(Iterator<Character> chars)| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswerGiving start string and end string, determine if start string can finally reach to the same as end string with below rules.
- ajay.raj January 18, 2018 in United States
For example:
"R L _ _ L R L"
"_": the space is empty
"L": this can only swap with the empty letter _ on its left side
"R": this can only swap with the empty letter _ on its right side
So, "R L _ _ L R L" can change to "R L _ L _ R L" , and can continue change to (if you want) "R L L _ _ R L". from: 1point3acres.com/bbs
The question is given these rules and the start string and end string, could we change the start string to end string (unlimited # moves as long as it is valid).
For example:
"R _ _ L R _ R _L"
can be changed to
"_ R L _ _ R R L _"| Report Duplicate | Flag | PURGE
Google Java Developer - 1of 3 votes
Answersgiven a list of points in a rectangular coordinate system, seeking any two points, such that all the remaining points will be in only one side of the line.
- ajay.raj January 15, 2018 in United States| Report Duplicate | Flag | PURGE
Google Java Developer - 1of 1 vote
AnswerYou are in the upper left corner, sitting in a boat, you want to reach to the lower right corner, but the matrix has a certain height at each location (i, j), and the boat can only go through the cell with water in it, looking for the earliest time that the boat can reach from the upper left corner coordinates (0,0) to the lower right coordinates (n-1, n-1). Each day, water goes up by one height unit
- ajay.raj December 03, 2017 in United States| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersSay you have an array for which the ith element is the price of a given stock on day i, you can buy stock at any day, but can only buy once a day, but if you sell the stock, you must sell all of them at once.
- ajay.raj December 02, 2017 in United States
Seeking maximum profit
public int maxProfit(int[] prices) {| Report Duplicate | Flag | PURGE
Facebook Java Developer - 0of 0 votes
Answersgiven a html file, compare if two html file show the same contents.
- ajay.raj December 02, 2017 in United States
Eg.
<html> <body> <p> H <i> ello </ i> </ p> <body> </ html> is typed as "Hello \ n" without regard to <i> , "\ n" because of <p>
follow up: what if the string is very long| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswerThe topic is to design a data structure to store employee relationships.
- ajay.raj December 01, 2017 in United States
For example, A is B's direct manager, there is an operation is "" set_manager "," A "," B ">.
For example, B is a colleague of C <"set_peer", "B", "C">
At this point, we do this with <query_manager "," A "," B "> and we get True, which means that A is B's manager (either direct or indirect).
This is true if we have <"query_manager", "A", "C">, because C is a coworker for B, so A is also C's manager. That is, there is a transitive relationship between colleagues.
Follow up, such as query <"query_manager", "A", "D"> (D this person has not been initialized), what to do. Conflict how to do
For example, A is a direct manager of B, E is a direct manager of C, which is set_peer (B, C), there will be conflicts, B and C direct manager should be the same person,
E and A are two people, there are contradictions here.| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
Answergiven a dictionary, output the longest List <String>. The result of a String is the previous String add a character at any position.
- ajay.raj December 01, 2017 in United States
example: {i, in, ing, sing, sting, string}| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
AnswersFind a “local minimum” in a binary tree
- ajay.raj December 01, 2017 in United States
a local min is a node whose value is smaller than that of any other nodes that are connected to it| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
Answers1. merge intervals with value
- ajay.raj December 01, 2017 in United States
PD: there are a series of continuous intervals, and each interval has a value. Initially, the ith
interval is (i - 1, i - 1), merge these intervals and return the result.
Merge Rule:
a. We can only merge the ith interval with i-1 th or i + 1 interval. The value of new interval is the
mean of these two original intervals.
b. Define cost as absolute difference of two neighboring intervals,
every time merge two intervals with the smallest cost.
c. If the smallest cost exceeds a threshold t, then stop.
d. There may be multiple valid result, just return one.
for example:
value: 3 7 6 5 1
intervals: (0,0) (1,1) (2,2) (3,3) (4,4)
threshold: t = 2
first iteration:
min cost = |7 - 6| = 1, notice that |6 - 5| is also okay.
after merging:
value: 3 6.5 5 1
intervals: (0,0) (1,2) (3,3) (4,4)
second iteration:
min cost = |6.5 - 5| = 0.5
after merging:
value: 3 5.75 1
intervals: (0,0) (1,3) (4,4)
second iteration:
min cost = |3 - 5.75| = 2.75 > t = 2, stop
return [(0,0), (1,3), (4,4)]| Report Duplicate | Flag | PURGE
Google Java Developer - 0of 0 votes
Answersfind the longest substring with at most k repeating characters,
- ajay.raj November 27, 2017 in United States
to make it more clear, at most k repeating characters means in the substring, the max count(frequency) of one or more chars is k| Report Duplicate | Flag | PURGE
Facebook Java Developer - 0of 0 votes
AnswerYou and your friend go to a game arcade where you choose to play the lucky pick game. In the game,
- Pooja August 09, 2017 in India
there is a square grid and on each block some money is placed on it. When a player chooses a block, the
machine randomly chooses a block from the available neighboring and the chosen block (consider 8
neighborhood). The player is awarded the money that is placed on the block that the machine selects.
Your friend needs help choosing the block.
Your job is to return the block position(s) that will maximize the minimum amount your friend will win
for sure. If there are more than one such block positions, then output must return all these positions.
Input Format
You will be given a single input representing the Grid Description (in the form of string array)
(N rows each containing N numbers separated by '#', each number representing the amount of money
put on that block)
Output Format
You need to return the array of string containing the position(s) of a block choosing which will give the
maximum amount of money which your friend will definitely win.
Sample Test Case 1
Sample Input
3 12#45#33 94#54#23 98#59#27
Sample Output
3#1
Explanation: In the above example, if he selects the block (3,1), then under the best case, he could win is
98 and under the worst case the maximum he could win is 54. In such scenario, the worst case of block
(3,1) gives your friend more money than the worst case of other blocks.
Sample Test Case 2
Sample Input 4
12#45#33#27
94#54#23#53
98#59#27#62
11#51#67#13
Sample Output
1#3
1#4
2#3
2#4
Explanation
Note: If the output array contains multiple strings(block's positions), all the positions must be in the
row-wise traversal order. In Example 2, the output is {1 #3,1#4,2#3,2#4}. If your function is returning an
array that has same elements (block's position) but in the different order, then the output array will be
incorrect.
Function to implement:
public static String[] amount_value(String[] input1){
//implement your logic
}| Report Duplicate | Flag | PURGE
IBM Java Developer - 1of 1 vote
AnswerRanjith is a newsoholic and reads news daily . Being a techie he is lazy and
- runbehindcode July 25, 2017 in India
loves to automate things.
Problem :
He collects a set of text documents containing news articles from all
around everyday.
He wants the news to be Categorize / clustered so that he can skip
categories he is not interested in and read his favorites.
Please help him do so by writing a program in language of your choice.
Predict category name in such a way that it should also work with any set
of news articles.
Input :
Collect a set of news articles as .txt files from domains such as Sports,
Politics, Business, Technology etc.. (One text file contains only one news).
Output :
Eg:-
File1.txt : CategoryName
File2.txt : CategoryName
File3.txt : CategoryName| Report Duplicate | Flag | PURGE
Java Developer - 0of 0 votes
AnswersCan you achieve the following without using enums? Given the last two lines stay the same.
- programmer July 12, 2017 in United Statesenum DayHalf { AM,PM; DayHalf dh1=DayHalf.AM; DayHalf dh2=DayHalf.PM; }
| Report Duplicate | Flag | PURGE
Facebook Java Developer - 1of 1 vote
Answerswrite a java program to solve sum of first three numbers is equal to sum of last three numbers.
- kancharlaratna July 10, 2017 in United States
String str="123" 1+2+3 and 3+2+1
String str="678786"
String str="1b8" not equal.| Report Duplicate | Flag | PURGE
Akamai Java Developer - -1of 1 vote
AnswersCreate a CostDomainObject named as CostDTO (like Data transfer object or value object) with
- Sameer July 10, 2017 in United States
three attributes, costId as type String and costAmout as type BigDecimal, effectiveDate as Date.
Override equals and hashcode methods based on costId.
Create Interface CostCalculator taking above CostDTO object as 2 Arguments
1) CostDTO add(CostDTO arg1, CostDTO arg2);
2) CostDTO subtract(CostDTO arg1, CostDTO arg2);
Implement the above 2 methods. You are creating those methods to sum up or subtract cost
amounts based on costId.
Throw a checked exception when the costIds are not the same.
Mostly what I am looking for is how you test your code. This is important as you will be
re-factoring/rewriting existing code or going to enhance existing functionality. We try to do test
first development| Report Duplicate | Flag | PURGE
Bank of America Java Developer - 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
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 - 0of 0 votes
AnswersHow many elements will the set object in the below snippet will contain after the program executes to last print statement?
- Flash May 13, 2017 in Indiapublic class ShortSetTest { public static void main(String[] args){ Set shortSet = new HashSet(); for(short i = 0; i < 100; i++){ shortSet.add(i); shortSet.remove(i-1); } System.out.println(shortSet); } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswerWhat would the output of the following snippet?
- Flash May 13, 2017 in Indiapublic class TrickyNum<X extends Number> { private X x; public TrickyNum(X x){ this.x = x; } private double getDouble(){ return x.doubleValue(); } public static void main(String[] args) { TrickyNum<Integer> a = new TrickyNum<Integer>(new Integer(1)); System.out.println(a.getDouble()); } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java - 0of 0 votes
AnswersQuestion 2: Write code for the following: given a text file containing this information (Date the customer logged-in, Tab, Customer ID) Example: 04/11/2017 \t 0003 04/12/2017 \t 0003 04/13/2017 \t 0004 04/13/2017 \t 0003 04/13/2017 \t 0003 04/15/2017 \t 0004
- mhannsari May 13, 2017 in United States
How to get the list of those customers that log in on four consecutive days?
Please give good solution| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersQuestion 1: Given input file with the following set of strings, Download input file: https://www.google.com/basepages/producttype/taxonomy.en-US.txt
- mhannsari May 13, 2017 in United States
Example: Electronics Electronics > Arcade Equipment Electronics > Arcade Equipment > Basketball Arcade Games Electronics > Arcade Equipment > Pinball Machine Accessories Electronics > Arcade Equipment > Pinball Machines Electronics > Arcade Equipment > Skee-Ball Machines Electronics > Arcade Equipment > Video Game Arcade Cabinet Accessories Electronics > Arcade Equipment > Video Game Arcade Cabinets Electronics > Audio Electronics > Audio > Audio Accessories Electronics > Audio > Audio Accessories > Audio & Video Receiver Accessories Electronics > Audio > Audio Accessories > Headphone & Headset Accessories Electronics > Audio > Audio Accessories > Headphone & Headset Accessories > Headphone Cushions & Tips Electronics > Audio > Audio Accessories > Karaoke System Accessories
write a function that stores this information. Your data structure should be able to provide information as Electronics = 14 Electronics > Arcade Equipment = 7 Electronics > Arcade Equipment > Video Game Arcade Cabinets = 1 Electronics > Arcade Equipment > Skee-Ball Machines = 1| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersWhat happens when you try to compile below class?
- Flash May 13, 2017 in Indiapublic class EnumTest { public EnumTest(){ System.out.println("Inside Constructor"); } public void printType(){ enum PrinterType {DOT,INK,LASER} } }
| Report Duplicate | Flag | PURGE
JP Morgan Java Developer Java