Tuesday 18 October 2011

Interview Puzzles I

1.There is a game which is being played by 2 persons A and B. The 2 players start the game keeping identical 50 paise coins on a blank board alternately. The 50 paise coins can be kept in the board such that no part of the coin is outside the board. It can touch the board edge but cannot protrude outside the board. The two players can place the coins anywhere on the board. The coins placed during the course of the game can touch each other at the periphery but cannot overlap with the already placed coins.

The player who has space to place the last coin is the winner i.e the player placing the last coin on the board with no space available for the opponent is the winner. If you are one of the players, what will your strategy be so that you definitely win?

Answer:-

1. I shall keep the 1st coin the exact centre of the board.
2. now after each coin that he keeps, I shall keep a coin exactly diagonally opposite. This shall reduce the space for his further attempts more than any other strategy.

2.Two guys A & B found out a old coin.on one side of that there is a picture of a king and on the other side it was written as 200B.C
A told that the coin is a fake one but B said the other way. so who is right and why?

Answer:-
A is right. How would the coin maker know that there were 200 years left for Jesus to be born before he even existed?

3.A man had three daughters. Another man asked him the ages of his daughter. He told that the product of their ages is 36.
Second man was confused and asked for another clue. First man told him that the sum of their ages is equal to his house number.
Second man did some calculations and was still confused. He asked for another clue. First man told him that his youngest daughter had blue eyes. On hearing this, second man immediately gave the correct Answer.

Question : What are the ages of his daughter ?

Answer:-
Ages:1,6,6

Solution:-
To begin with, there is a small logical assumption that all the ages are integers.

4.Further to this, it is given that the product of the daughters' ages is 36. This gives the man just 8 possibilities:

AGE 1 AGE 2 AGE 3 SUM OF AGES
1 1 36 38
1 2 18 21
1 3 12 16
1 4 9 14
1 6 6 13
2 2 9 13
2 3 6 11
3 3 4 10

The correct solution has to exist within this range possibilities because the man could guess the same.

Calculation of the sum of their ages (the rightmost column) shows the only possible instances of the house no. If the sum were 38, 21, 16, 14, 11, or 10, he would have been able to guess the ages immediately. He was not able to do so only because the number of the house and the sum of the ages was 13! (This is because, even after this hint the solution was not unquely deducible…!!) Because of this, he did not have a unique solution until the man informed her about his youngest daughter.

It becomes clear that there is no ambiguity at this "youngest"position and that not two of them are tied at this position ( in case the ages would have been 9,2, and 2) . This is possible only if Kiran's daughters are 1, 6, and 6 years old.

With similar arguments, assuming no tie at the eldest position the correct set of ages would be 9, 2, 2.



5.Long back there was a king..
He had a very pretty daughter
He decided to hold a Svyamvar for his daughter
He called everyone but forgot to call a magician
Magician was very angry . He kidnapped the king's daughter.
King was very upset . He goes to the magician and pleads before him.
The magician , being soft at heart , tells the king that :
" O great King!! I agree to return your daughter back.
I 'll turn her into a flower and place her in your garden tomorrow morning.
You come there tomorrow morning.
If you are able to recognise her then I will return her back to u"

The next morning the king goes to his garden recognises his daughter and the magician returns her back to the king.
The question is how did the king recognise his daughter???
Some pts. to be noted:
1.The garden had all the species of flowers so the daughter was just like any other flower.
2. There are no tricks . The Answer is purely based on logic.

Solution:-
The king was very clever. When he heard that he "had" to recognise her daughter "flower" the next morniong, he decided to play a game with the magician. He went to the garden quitely late in the night and made some mark on all the flowers that existed there already. So when he came back to the garden the next morning, the task was cut out simple for him. He had to only look for a flower w/o that mark. And EUREKA...He found it.
What about all the flowers that Bloomed overnight? After marking all the flowers he also nipped all the Buds. This way he would be having a higher probability in identifying his daughter.



6.A man is trapped in a room.The room has 2 doors and 2 guards on those doors.One guard always speak true and the other always lie.Out of the two doors one goes towards escape and one towards jail. The man does not know which guard is lier and on which door and of course which door opens where. Fortunately,he has given a chance of escape by asking only one question to any of the guards.
Now the question is what question the man should ask?

Solution:-
Suppose the situation is

Gaurd 1 stands at Door 1 and Guard 2 stands at Door 2

The man should ask the Guard 1 this question -

" What will be the Answer of the Guard 2 when I ask him where does door 2 lead to?"

case 1:

If the Guard 1 Says "Guard 2 will say - towards JAIL" -
then the Door 2 will take him outside

Case 2:

If the Guard 1 Says "Guard 2 will say - towards outside" -
then the Door 1 will take him outside



7.A king has 100 sons(not dhritarashtra) and he wants a real fundoo girl to become his daughter-in-law. so he sets a plan. a certain amount is fixed for each son. (this much amount is to be given to the girl who marries that particular son). after that he invites a girl. the condition is that each son will be prsented to the girl and his amount will be told. you can choose any son randomly and after knowing the amount you can either accept or reject the guy. and go for another one, again randomly. but you can't go back to a previously rejected guy. the question is to get the maximum amount what will be your strategy?

The music stopped. She died. Explain

Answer:-
She was on LSS(Life Support System) and there was no UPS or power back up. The music stopped as the power went boom!

8. A man goes to a restaurant and orders Albatross Soup. The waiter brings the soup. The man tastes it, comes out of the restaurant and shoots himself. Why?

Reason: Albatross soup (variant 1.2 of 18 available across the globe) served in that hotel was extremely hot and poisonous. Got him all "fired" up. Didn't prolong the agony and shot himself.

9. A man wakes up in the morning, goes to a place, takes three left turns in succession and meets a masked man. What is the profession of the first man?

Profession: Good Samritan 4 times over.
Reason: The man had done 4 "right" turns (good deeds) the previous day so to make for the imbalance, he did 3 "left" turns and met his long lost friend Long Gone Silver whose face got burnt during the fire at the theatres on Friday the 13th, October 1999.

10.A Jailor has three bullets and he has four prisoners
The three of them are standing on the stairs one on first staircase second on second and the third on third& the fourth prisoner is made to sit in a closed room with no windows in proper security Jailor make the prisoners wear a cap,two of red colour & two of white He gave them a cap each No body knows about the colour of their cap neither can they see it
He declares that in his count for three if anyone of them will tell
the colour of his cap,he will spare him
You have to simply find that who is that lucky guy ???

Solution:-
i assume that the jailor will spare only the person who tells the colour of the cap first if he is right. also there is something worse than death to dissuade people from making false calls. and lastly that the lucky person is eager to get the ordeal over and if somebody knows the colour of his cap he will speak up immediately.

now under these assumptions:
the fourth person is helpless as he cannot see anything and due to the symmetry the replies do not give him any extra indicatons.

the third person sees two caps and if they are the same colour he speaks up immediately. now even the second person knows the colour of his cap as it is the same as the colour of the first persons cap, but unfortunately the lucky berth is gone.

if the first two are wearing different coloured caps the third is helpless and hence doesnot speak up. now the second person can infer the colour of his cap from the colour of the cap worn by the first person and speaks up and is spared.

so depending on the colours of the first two caps either the second or the third person is spared. now to determine the lucky guy we need the probablity of the first two guys getting a cap of the same colour which is 1/3, where as that they get different colour has 2/3 probablity and so the 2nd person could be called the luckiest if you wish!!

Java Important Interview FAQ

What are Encapsulation, Inheritance and Polymorphism?- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.
What is OOPs?- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.
What are Class, Constructor and Primitive data types?- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
What is an Object and how do you allocate memory to it?- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
What are methods and how are they defined?- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.
What is the use of bin and lib in JDK?- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

What is casting?- Casting is used to convert the value of one type to another.


How many ways can an argument be passed to a subroutine and explain them?- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.


What are different types of access modifiers?- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.

What is final, finalize() and finally?- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.

What is UNICODE?- Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.


What is Garbage Collection and how to call it explicitly?- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.

What is finalize() method?- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

What are Transient and Volatile Modifiers?- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.


What is method overloading and method overriding?- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.


What is meant by Inheritance and what are its advantages?- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.

What modifiers may be used with top-level class?- public, abstract and final can be used for top-level class.

What are inner class and anonymous class?- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

What is a package?- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.

What is a reflection package?- java. lang. reflect package has the ability to analyze itself in runtime.

Written interview apptitude Questions II

46. Six swimmers A, B, C, D, E, F compete in a race.
The outcome is as
follows.
i. B does not win.
ii. Only two swimmers separate E & D
iii. A is behind D & E
iv. B is ahead of E , with one swimmer intervening
v. F is a head of D
1. Who stood fifth in the race ?
(a) A
(b) B
(c) C
(d) D
(e) E
Ans: (e)
2. How many swimmers seperate A and F ?
(a) 1
(b) 2
(c) 3
(d) 4
(e) cannot be determined
Ans: (d)
3. The swimmer between C & E is
(a) none
(b) F
(c) D
(d) B
(e) A
Ans: (a)


4. If the end of the race, swimmer D is disqualified
by the Judges
then swimmer B finishes in which place
(a) 1
(b) 2
(c) 3
(d) 4
(e) 5
Ans: (b)
47. Five houses lettered A,B,C,D, & E are built in a
row next to each
other. The houses are lined up in the order A,B,C,D, &
E. Each of the
five houses has a colored chimney. The roof and
chimney of each
housemust be painted as follows.
i. The roof must be painted either green,red ,or
yellow.
ii. The chimney must be painted either white, black,
or red.
iii. No house may have the same color chimney as the
color of roof.
iv. No house may use any of the same colors that the
every next house
uses.
v. House E has a green roof.
vi. House B has a red roof and a black chimney
1. Which of the following is true ?
(a) At least two houses have black chimney.
(b) At least two houses have red roofs.
(c) At least two houses have white chimneys
(d) At least two houses have green roofs
(e) At least two houses have yellow roofs
Ans: (c)
2. Which must be false ?
(a) House A has a yellow roof
(b) House A & C have different color chimney
(c) House D has a black chimney
(d) House E has a white chimney
(e) House B&D have the same color roof.
Ans: (b)
3. If house C has a yellow roof. Which must be true.
(a) House E has a white chimney
(b) House E has a black chimney
(c) House E has a red chimney
(d) House D has a red chimney
(e) House C has a black chimney
Ans: (a)
4. Which possible combinations of roof & chimney can
house
I. A red roof 7 a black chimney
II. A yellow roof & a red chimney
III. A yellow roof & a black chimney

(a) I only
(b) II only
(c) III only
(d) I & II only
(e) I&II&III
Ans: (e)
48. Find x+2y
(i). x+y=10
(ii). 2x+4y=20
Ans: (b)


49. Is angle BAC is a right angle
(i) AB=2BC
(2) BC=1.5AC
Ans: (e)
50. Is x greater than y
(i) x=2k
(ii) k=2y
Ans: (e)

Search here for "Freshers Jobs"