Java Developer Interview Questions
- 0of 0 votes
AnswersFrom a given input array, for each element, find next higher element present in each array. for example {40,50,11,32,55,68,75} output should be {50,55,32,55,68,75,-1} for element if no higher element is present, print -1. complexity should be less than O(n^2) . you can use datastructure and no constraint on space complexity.
- OTR November 01, 2013 in India| Report Duplicate | Flag | PURGE
iLabs Java Developer Algorithm - -1of 1 vote
AnswersI am capturing the voice as buffer at client side and sending that buffer to server using Socket programming, then at server side I receive it and play using SourceDataLine , and its properly running on LAN but when I deploy it to Remote Server the voice carry noise data.
- zsanchit October 22, 2013 in India
tell me the solution.| Report Duplicate | Flag | PURGE
Java Developer Java - 0of 2 votes
AnswersWrite a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
- java.strat October 16, 2013 in United States
For numbers which are multiples of both three and five print "FizzBuzz".
Additionally, instead of printing "Fizz" or "Buzz", create a lookup such that 3 --> "Fizz", 5 --> "Buzz", 7 --> "Woof" and so on. The signature of the method would be:
List<String> fizzbuzz(int start, int end, Map<Integer, String> lookups) { ..}
The expected output is of the format : 15:FizzBuzz, 21:FizzWoof, 105: FizzBuzzWoof, etc| Report Duplicate | Flag | PURGE
Java Developer Algorithm - -2of 2 votes
AnswersAsked question on expansion of {2x-3y}^3 ?
- java.interviews.questions October 16, 2013 in India
and equation of line?| Report Duplicate | Flag | PURGE
Citigroup Java Developer Math & Computation - 0of 0 votes
AnswersDifference in SOAP and IIOP?
- java.interviews.questions October 16, 2013 in India| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
AnswersWhat is externalizable interface?
- java.interviews.questions October 16, 2013 in India| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
Answersjava code to calculate size of String without using any length or size method?
- java.interviews.questions October 16, 2013 in India
String input = "abcde ";
int output = 5;| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 0of 0 votes
AnswersWrite code in java to move char to next position with minimum space requirement?
- java.interviews.questions October 16, 2013 in India
String input = "abcde";
String output = "eabcd";| Report Duplicate | Flag | PURGE
Citigroup Java Developer Java - 5of 7 votes
AnswersInput - array of integers size N, integer Threshold. Output - the number of pairs (x, y) of distinct elements with condition x + y <= Threshold. Is that possible to implement it with O(n) ?
- anonymous October 04, 2013 in United States| Report Duplicate | Flag | PURGE
Google Java Developer - -1of 5 votes
AnswersWrite a comparator which can be used to compare any type of objects?
- java.interviews.questions September 20, 2013 in India| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Java - 0of 0 votes
AnswersDesign high throughput trading application? Application is hosted in NY and we have traders all over the world accessing this application. What things we need to take care on designing this application.
- java.interviews.questions September 11, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 0of 2 votes
AnswersIf we have unsorted list of numbers like
- java.interviews.questions September 11, 2013 in India
3,1,4,7,9,4,7,4,9
best way to figure out if number n exists in the list? they were interested in constant time performance| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer - -1of 1 vote
AnswersRemoving duplicates from unsorted list of integer?
- java.interviews.questions September 11, 2013 in India
if you have unsorted list of
0,5,9,5,6,7,6,9
the result should be
0,5,9,6,7 and the performance should be best over more number of elements.| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Algorithm - 0of 0 votes
AnswersHow to create singleton class and what if the constructor is throwing IOException? what will be best strategy to create instance of this class?
The question is more on constructor throws exception.
- java.interviews.questions September 11, 2013 in United States//create singleton class. private SingltonExample() throws FileNotFoundException { File f = new File("data.txt"); FileInputStream fis = new FileInputStream(f); }
| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 1of 1 vote
Answersexplain if this method is thread safe?
- java.interviews.questions September 11, 2013 in United Statespublic static void myMethod(StringBuilder sb){ // StringBuilder is not thread safe.. }
| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer - 0of 2 votes
AnswersThere is an sorted array suppose 10 20 30 40 50 60 70 80 90. If we rotate it n times(suppose n = 3 in my case). The array will be 70 80 90 10 20 30 40 50 60. The total no of values which are not in right position 3(in this case which are 70 80 90) so we have to make a generalized solution. I was able to answer this in O(n) but he wants something which is lesser than O(n).
- tarunverma August 23, 2013 in India| Report Duplicate | Flag | PURGE
Akamai Java Developer Arrays - 0of 0 votes
AnswersI have an array containing duplicates in the following format:
arr[]={ 2,9,1,5,1,4,9,7,2,1,4 }
I want to sort the array in place such that all the duplicate elements are moved towards the end and sorted in different sub arrays like following:
arr[]={ 1,2,4,5,7,9, 1,2,4,9, 1 }
There is no range for integers for the array specified. Following is the code which i tried. This code recursively sorts the subarrays and then move duplicates towards the end. But Complexity wise this is not optimal solution.
Please suggest if it can be solve in O(n) or O(nlogn). Entire code is as follows:
- ronansaini August 15, 2013 in Indiapublic static int sortDuplicates(int a[],int start,int end){ int i, k,temp; if(start==end) return 1; Arrays.sort(a, start, end); k = start; for (i = start+1; i < end; i++) { if (a[k] != a[i] && a[k]<a[i]) { temp=a[k+1]; a[k+1] = a[i]; a[i]=temp; k++; } } return sortDuplicates(a,k+1,a.length); }
| Report Duplicate | Flag | PURGE
United HealthGroup Java Developer Algorithm Arrays - 1of 1 vote
Answers/*
- thomascom136 August 03, 2013 in United States
Random set of WORD.
Criterion : Given a word find out if the word can be broken into smaller word, by removing one alphabet at a time.
a) all such word should be valid dictionary word.( Assume a function is there to test whether the word exist in dictionary)
b) Remove one alphabet at a time but the new word need to be in dictionary.
For eg :
restated -> restate -> estate -> state -> stat -> sat -> at -> a
fullfill the criterion. ( single alphabet assume belong to dict)
My solution below. I assume it can be done using dynamic programming or trie data structure
*/| Report Duplicate | Flag | PURGE
Google Java Developer Algorithm - 3of 3 votes
AnswersI need to store countries, its states and cities in a data structure.
- krupaljpatel July 24, 2013 in United States for Risk
The following queries might be used to fetch details
1) find list of states for a country.
2) find list of cities for a state.
3) find the name of the country and state for a city.
eg:
1) India -> Gujarat, UP, MP
MP -> bhopal,indore
Gujarat-> Surat,Ahmedabad, Baroda
2) USA -> Texas, California.. and so on.
Which is the best data structure that can be used to store these details.| Report Duplicate | Flag | PURGE
Morgan Stanley Java Developer Data Structures - 1of 1 vote
AnswersFind the longest substring that is the same in reverse.
As an example, if the input was "I like racecars that go fast"
the answer would be "racecar".
Test your code in the following String:
- Prithvi July 11, 2013 in United States"FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth"
| Report Duplicate | Flag | PURGE
Java Developer Algorithm - -3of 3 votes
Answersclass Test { public void m1(String arg1){ arg1 = "Am I going to disappear?"; } public static void main (String[] args) { Test test = new Test(); String iAmOfAnArgumentativeNature = "I am born new"; m1(iAmOfAnArgumentativeNature); System.out.print(iAmOfAnArgumentativeNature); } }// end class
What is the output?
- SoMiE July 11, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 1of 1 vote
AnswersImplement Object Pool for database connections in the following interface
interface Pool{ public Connection get() public void put(Connection c) }
It should have object pool characteristics.
- SoMiE July 11, 2013 in India
Hint - The emphasis is on which data structure you will use to achieve this.| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Data Structures - 0of 0 votes
AnswersIf a java class has methods declared
as followsclass A public synchronized void m1() { //whatever code } public synchronized void m2 { // whatever code } // note that return type is not relevant here.
if a class is created with A a = new A() and
- SoMiE July 11, 2013 in India
if a thread T1 is executing a.m1 and another thread T2 wants to execute a,m2 - what will happen?| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - -3of 3 votes
AnswersA set of milk containers has capacities of 5, 4, 3, 2 , 1 etc . Lets say X containers
- SoMiE July 11, 2013 in India
There is another set of Y containers
If you are going to transfer water from one to the other and each transfer has a fixed cost C, evaluate and state the complexity of the algorithm to achieve a least cost transfer.| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Algorithm - 4of 4 votes
AnswersHow will you calculate the size of the object in java ? I gave answer for the serialized objects. The interviewer then modified the question that an ArrayList contains 10 non-serialized objects. How will you find out which object is the heaviest one ? He again added that the ArrayList is not a generic one, it may contain any kind of object like Organisation, Employee, Salary, PersonalDetails,OfficialDetails etc all object type. Now you have to find out which one is the heavy object through java program. He said there is some way you can measure the size of the object. Please help me.
- Mr D July 09, 2013 in India| Report Duplicate | Flag | PURGE
Goldman Sachs Java Developer Java - 2of 2 votes
AnswersGiven an NxM (N rows and M columns) integer matrix with non-negative values (0..MAX_INT inclusive). What is the maximum sum from going top left (0, 0) to bottom right (N-1, M-1) ? The condition is that when you're at point (p, q), you can only move to either right (p, q+1) or down (p+1, q).
- math.matt July 03, 2013 in United States
Expected time complexity O(N*M)
Expected space complexity O(N+M)
From the space complexity it looks like there is a DP solution, but I couldn't figure it out.| Report Duplicate | Flag | PURGE
Samsung Java Developer Matrix - 0of 0 votes
Answersgiven two very big files , each having around 1 billion lines , u have to print all the lines that are common to both files . Please suggest a good optimal approach
- Mystic June 14, 2013 in United States| Report Duplicate | Flag | PURGE
Amazon Java Developer - 0of 0 votes
AnswersWrite a writer thread and a Reader that share a fixed-size buffer and an index to access the buffer .The writer should place numbers into the buffer while the Reader thread should remove the numbers.The order in which the numbers are added or removed is not important.
- Mystic June 12, 2013 in India| Report Duplicate | Flag | PURGE
United HealthGroup Java Developer