1. There are 100 hundred doors numbered 1, 2, 3 ,4 ,..... 100 n one person is standing in front of each of them. Initially all are in open state.'
1 goes n closes all the doors
2 goes n flips the state of all doors numbered 2,4,6, ....
3 foes n flips the state of all doors numbered 3,6,9,. ...
What would be the state of each door after al the persons have flipped the doors ..
Ans : All doors which are squares f any number wil be closed(or open .. not sure ) coz wen we see their factors , same number appears
twice ,, this problem is related to number of factors
Q: We have an array in which numbers are sorted.
Given a number k, we need to find a pair of numbers from the numbers present in the array such that their difference is k
in least time ..
Ans :
Complexity : O(n logn)
As we know the difference, we ll start from first element and add k to it and then search for k in the remaining array.
we can apply binarry search on the remaining elements as we know they are sorted.
Q : Write algo to find all possible permutations of a given character array e.g for a String abcdef
A string of n characters will have n! permutaions.
Q: Write algo to reverse all words given in a String. in O(n)
Q:What are volatile variables are why are they used ?
Ans : The answer to this is realted to persistence in java. Volatile variables are not persisted in DB.
e.g. lets say we have three variables v1,v2 and v3.
Out of these , V3 is volatile.
So everytime a user makes changes to these variables , changes made to only v1 and v2 will be persisted, but v3 wont be.
Q: How can you find out a loop in a Liked list ?
Ans : It can be done by using two pointers .... one would move ahead by one node n other by two nodes., but in this case , if number of elements in the loop is large ,
it would take a lot of time ... we would keep looping into the loop ..
so to handle this, we should associate a variable with each node n set it wen we traverse the node , if during traversal, we encounter
a node which has already been traversesd, then we have found the loop.
Q: We have an array having numbers in increasing order but they are repeated e.g. 1,1,1,3,3,3,5,5,9,9,9
Find all unique numbers.
Ans : I used integer array in this for output, but ArrayList should be used instead as it would be more space efficient as we donot know
the number of elements in output. THis had to be done in O(n) complexity.
Apart from this, there were a number of java questions in written test.. which were quite tricky..like finding output
and which of the following statements are correct etc.
They asked basic java questions n examples of inner classes , Threads , static variables, overriding was their favourite ques
Solve SCJP ques for this ...
1 goes n closes all the doors
2 goes n flips the state of all doors numbered 2,4,6, ....
3 foes n flips the state of all doors numbered 3,6,9,. ...
What would be the state of each door after al the persons have flipped the doors ..
Ans : All doors which are squares f any number wil be closed(or open .. not sure ) coz wen we see their factors , same number appears
twice ,, this problem is related to number of factors
Q: We have an array in which numbers are sorted.
Given a number k, we need to find a pair of numbers from the numbers present in the array such that their difference is k
in least time ..
Ans :
Complexity : O(n logn)
As we know the difference, we ll start from first element and add k to it and then search for k in the remaining array.
we can apply binarry search on the remaining elements as we know they are sorted.
Q : Write algo to find all possible permutations of a given character array e.g for a String abcdef
A string of n characters will have n! permutaions.
Q: Write algo to reverse all words given in a String. in O(n)
Q:What are volatile variables are why are they used ?
Ans : The answer to this is realted to persistence in java. Volatile variables are not persisted in DB.
e.g. lets say we have three variables v1,v2 and v3.
Out of these , V3 is volatile.
So everytime a user makes changes to these variables , changes made to only v1 and v2 will be persisted, but v3 wont be.
Q: How can you find out a loop in a Liked list ?
Ans : It can be done by using two pointers .... one would move ahead by one node n other by two nodes., but in this case , if number of elements in the loop is large ,
it would take a lot of time ... we would keep looping into the loop ..
so to handle this, we should associate a variable with each node n set it wen we traverse the node , if during traversal, we encounter
a node which has already been traversesd, then we have found the loop.
Q: We have an array having numbers in increasing order but they are repeated e.g. 1,1,1,3,3,3,5,5,9,9,9
Find all unique numbers.
Ans : I used integer array in this for output, but ArrayList should be used instead as it would be more space efficient as we donot know
the number of elements in output. THis had to be done in O(n) complexity.
Apart from this, there were a number of java questions in written test.. which were quite tricky..like finding output
and which of the following statements are correct etc.
They asked basic java questions n examples of inner classes , Threads , static variables, overriding was their favourite ques
Solve SCJP ques for this ...
No comments:
Post a Comment