## Tuesday, October 8, 2013

### ten friends 10 apple.. but 1 remain in basket

Travelling in bus. Sitting near window. Enjoying weather.
But its a puzzle time for u all...

You have a basket containing ten apples. You have ten friends and each desire an apple. You give each of your friends one apple. After a few minutes each of your friends has one apple each, yet there is an apple remaining in the basket.How?

From www.jobpuzzles.com

(for answer check again after atleast 24 hours. In case u think u hit an answer..pls post)

### city name... soap fruit city bird face student

Solve this word game puzzle.

1. I am a 11 letter Indian city.
2. Last 6 letters is fruit name.
3. 7,8,3 letters is a bird name.
4. 6,7,5,3 is an organ in the face.
5. 1,8,3 is used 4 studnt
6. 9,5,3 is a soap name

101% brain work.

From www.jobpuzzles.com

Answer: it would be better to solve first.
But in case you are so eager then *********For answer scroll down....

## Friday, August 30, 2013

### Box Having Defective Balls. 10 Box 1 Chance.

You have been provided with 10 boxes. Each are full of balls and each ball weighs 10 gm.

One of these box has all defective balls. That is each ball in that box is of 9 gm.

You are also given a weighing machine. It is a digital electronic machine that shows weight of howsoever numebr of balls kept on it. That is if you put 'n' balls on it, it will tell you the total weight of n balls. And machine is big enough to accomodate any number of balls.

You have only one chance to weigh.

How will you find the box that is defective balls container.

### Moving Ants in Triangluar spiral - Classic Puzzle

There are three ants.

They are sitting on the three corners of an equilateral triangle.

If each ant randomly picks a direction. And start moving along the edge.

What is the probability that no two ants collide?

### 100 Prisoners - Set Free or Hanged Challenge

Suppose there are 100 prisoners. They all are in the prison in solitary cells. The jailor/admin of the prison offered them a challenge. He says that he will put one prisoner per day, selected randomly into a special room with a light bulb and a switch which controls the bulb.

A prisoner can be selected more than once.
No other prisoners can see or control the light bulb.
The prisoner in the special room can either turn on the bulb, turn off the bulb or do nothing.

On any good day the prisoners can feel winning and stop this process and say that every prisoner has been in that special electrical room at least once.

If that happens to be true, all the prisoners will be set free. But if it is false, then all the prisoners will be executed.

What should the prisoners do to win the challenge and come out!!
(PS: Police should take ownership that they wont do the crime again. Hehehe)

### Generate random 7 from random 5

Write a function to generate a random number between 1 and 7. You have been given a function that generates a random number between 1 and 5. The distribution between each of the numbers must be uniform.

### Bird Running Between Trains - Classic Puzzle

It is a classic Puzzle. And it can be seen all over the internet.

A train leaves City X for City Y at 15 mph. Same instant, another train leaves City Y for City X at 20 mph on the same track. (There will be an accident. Huh...)

At the same moment, there is a bird that was sitting on the engine of train at city X. It leaves the train and flies towards the City Y train  at 25 mph. When the bird reaches the train from City Y, it immediately reverses its direction.

It then continues to fly at the same speed towards the train from City X, when it reverses its direction again, and so forth. The bird continues to do this until the trains collide. How far would the bird have traveled in the entire to and fro journey.

### Bridge Crossing - Different Speed - 1/2/7

There are Four persons. They need to cross a rickety bridge at night.

They have only one torch and the bridge is too dangerous to cross without one. The bridge is only strong enough to support two people at a time. Not all people take the same time to cross the bridge.

Each person takes different time to cross bridge. Times for each person are  1 min, 2 mins, 7 mins and 10 mins.

What is the shortest time needed for all four of them to cross the bridge?

### Atleast One Husband is Cheating!!

A certain community comprises of 100 married couples only. Everyone lives with the following rule:

1. If a husband cheats on his wife, the husband is executed as soon as his wife finds out about him.
2. All the women only gossip about the husbands of other women.
3. No woman ever tells another woman if her husband is cheating on her.
So every woman knows about all the cheating husbands in the town except her own.

(It can also be assumed that a husband remains silent about his infidelity. )

One day, the leader of that small society/community announces that there is at least one cheating husband in the town.

What do you think happens?

## Tuesday, March 12, 2013

### New Technical Terminology Puzzle - JobPuzzles.Com

Question:
Everyone around wants to use me.
Everyone wants to share things with me.
I will make them there things delivered anywhere.
Earlier also they had people similar to me, but they were kept close.
I am far, and not close.
Yet everyone wants me.
Who am I??

I will post later. This is easy
Anyone???

### Set HSB of Unsigned Integer Zero

On My one of the Interview Stint with Adobe, I read a programming or technical puzzle by Mr. Denis ZabavchikI have also been recommended this puzzle by my seniors presently scattered in Sunny Vale, Palo Alto, and Bangalore.
The question is to  set the highest significant bit of an unsigned integer to zero. You are intended to write a macro for that. Comeon, Techies. Get the Job Done!!

Solution:
#define Set_HSB_ZERO(h) \
(h&=(h>>1)|(h>>2), \

h|=(h>>2), \

h|=(h>>4), \

h|=(h>>8), \

h|=(h>>16))
Smile!!

### Little House, All Alone, Break Wall to Live : Classic riidle

Now there is one childish Riddle.
Who knows you get to answer this at certain interviews. Technically because your interviewers might be reading this Website. :)

Question:
I have a little house in which I live all alone.
It has no doors and windows.
And if I want to go out I must break through the wall.
Though I am living in my house, but for actual living I have to go out!!
Who am I??

It is chicken before birth. Living in Egg.:)

### Solution to Seven Pieces, Two Cuts - Gold Puzzle at JobPuzzles.Com

This post is Solution to Seven Pieces, Two Cuts - Gold Puzzle at JobPuzzles.Com
For question Refer to :
Original 7 Piece 2 Cuts Gold Bar Paying Problem at JobPuzzles.Com

What you can do is to divide the 7 piece gold bar to make a piece of following sizes:
-->1 part (Say A)
-->2 part  (Say B)
You have used your two cuts, that you were allowed to do
--> third will be automatically of 4 parts  (Say C)

And now you can pay him at end of each day by help of these divided parts.
For eg.
On First Day--> Give A
On Second Day--> Take A give B
On Third Day--> Give A
On Fourth Day--> Take A and B, and give C
..
..
Now you know the answer. So complete it.

### Pointer Arithmetic Interview Puzzle at Job Puzzles.Com

Pointer Arithmetic Question for technical interviews.
I am also giving solution to this, but it is adviced to see the solution only after trying for sometime.

Question: What will be the output of following code and how.

void main()
{
int *p,*q;
p=(int *)40;
q=(int *)60;
printf("%d\n",q-p);
}

It is 6-40=20
and then 20/2 =10
Think How!!

### Seven Pieces, Two Cuts - Gold Bar Puzzle

You have engaged someone for seven days for some work. And, you have a gold bar to pay him.
(God!! what is that work?? Anways that is not my puzzle!!)

The gold bar is divided into seven connected pieces. That is you can easily break them in seven equal pieces, but still they are loosely joined.
You have to pay him a piece of gold at the end of every day.

Question: You can make only two breaks in the gold bar. Then how will you pay him.

I have dedicated another post for the solution.
Solution to the 7 Pieces 2 Cuts Gold Bar Paying Problem at "Puzzles in Job Interviews"
First think and try to solve before jumping to the answer.

### Not Tells, Not Knows, Not Wants - what???

Tickling Riddle:

You will be amazed to know that this Puzzle which has been around over the internet, has been asked by one candidate appearing for a Financial High Profile Job Function.

Question:
One who has it does not tell it.
One who takes it does not know it.
One who knows it does not want it.
What is that??

Its Money!!

Confused? I am also Kidding. It is Counterfeit Money!!
Satisfied!

### Equal Division of Cake with Rectangular Piece Removed

Problem:
You are given a rectangular cake with a rectangular piece removed.
The piece removed can be any size or orientation.
How will you cut the remaining cake into two equal halves with one straight cut.

|------------
|              |
|      ____|
|___|

Solution: Now if you want a witty answer, just cut the cake at its width. ie. Look the cake fro its side. Lets say cake is 10 cm thick, cut it from 5ck thickness mark
:)
There is one more answer for Pure mathmaticians.
Anyone??

### Twice in week, Once in Year

This is Second in a "Week Year Minute But Not : Classic Word Riddles"

Questions:
What comes twice in a week, but once in a Year?

In a different Post:

Solution To Twice in Week, once in Year Puzzle at JobPuzzles.Com

### Solutions to "Week Year Minute But Not : Classic Word Riddles"

This is answer to previous puzzles:

Question 1:
What comes once in a minute, twice in a moment, but never in a hundred thousand years?
The Letter 'M'

Question 2:
What comes twice in a week, but once in a Year?
Come on, Now that is easy!!
The Letter 'E'

### Run and Wet, Still but Dry Puzzle

Job Puzzle:
There were five men went to church.
Suddenly, it started to rain.

The four men who ran got wet,
And the one that stood still stayed dry.

How?

Might be they were 4 men and a dead man in coffin. So he was dry.

I have an exclusive answer too, that relates to Management Professionals. Can anyone guess??

### once in a minute, twice in a moment, but never in a hundred thousand years

This is First in a "Week Year Minute But Not : Classic Word Riddles"

Questions:
What comes once in a minute, twice in a moment, but never in a hundred thousand years?

In a different Post:
Solution to Once in Minute but not in thousand Years Riddle at JobPuzzles.Com

### Gets Wet While Drying

Riddle:
What gets wet while drying.

Is there other. Let us see your wit here...

### 100 Camels 7 Poles Solution

There was a question asked in Earlier 100 camels 7 poles Question On this Website

Question: How can you tie 100 camels in 7 poles such that each pole has odd numbers of camels.

See when there are odd number of poles, you cannot tie odd numbers of camels on each pole to get an even number 100

So, it is not possible

### Come from Mine, Caged in Wood : Classic

Question:
I come from a mine...
and caged in a wooden case...
A case from which I am never released...
and yet I am used by almost everybody.
And before using me people try to release me from my case.

But after sometime, I again go into that wooden case.

You have to sharp it befor using
And then it again gets used up, and goes inside the wooden wrap.

### Tie 100 Camels in 7 poles : Classic

Now this puzzle has been around for several years. I learned this even before I knew these can also be asked in any interviews.

I don't remember who (Mom, Dad, or relative) asked me this. But here it goes. And, Yes ; This has been asked recently in a US Startup firm here in Bay Area

Question: How can you tie 100 camels in 7 poles such that each pole has odd numbers of camels.

See this is a simple question.
I want you to think.
And I dont want anyone asking this to me over the email, so I have separate blog post for solution.
Discuss here, solve here or goto following for the solution!!
Solution to 100 Camels 7 Pole problem at JobPuzzles.Com

### Algorithm to Reverse Linked List - Classic

This is a classic programming puzzle, posed to many and different palces.

Companies in love with this question: Adobe, Microsft, Amazon, Microsoft
Google has changed this question. (in some other post)
Facebook asks an implementation of this in another problem (That Facebook puzzle and its solution some other time)

start : iterative loop
curr->next = prev;
prev = curr;

curr = next;

next = curr->next

endloop

Another solution can be by using Recursive function:
Just watch the "Base condition" of this algorithm
recursive_solution(ptr)
if (ptr->next == NULL)

return ptr;

temp = recursive_solution(ptr->next);

temp->next = ptr;

return ptr;

end

### Two People Running same speed. Yet who wins - Time and distance Classic Puzzle

Silvia and Charlotte have exact speeds for walking and running - neither Silvia outwalks Chalotte, nor Charlotte outruns Silvia.Technically, same speed.
But for a given distance, Silvia runs half the time, then walks another half.
Wheras, Charlotte runs half the distance, then walks another half.
If they were to compete, who wins.

Remember Speed Distance philosophy :) taught in Highschhol
Hint there will be two times when once Silvia wins and after sometime Charlotte wins. Find when and how.

But just for your start I give you a simple resolution, that may help you win an interview at most places. Though the answer is not perfect in itself. Still :)
If Charlotte runs half the distance and walks the second half, her second part will take longer. Since Silvia is running half the time, she will always run a further distance than Charlotte before he starts walking. Since they walk the same speed, Charlotte will not be able to catch her.

### Determine or find duplicates in an Array

Question:
Given an array of length N containing integers between 1 and N, determine if it contains any duplicates.
Obviously I have posted a solution in an earlier post. Search that in this website.
But the point is "Is there an O(n) time solution that uses only O(1) extra space and does not destroy the original array?"
Anyone???
My email Id. Huh!! If you can't find from this website, you are not understanding that you are not solving a simple puzzle of finding an email id. Cumon now, find that!!

### Xalloc Vs Yalloc - if X='m' & Y='c'

There can be an interviewer who can throw you a question like:
Xalloc Vs Yalloc - if X='m' & Y='c'

i.e Differentiate between both

Now this is a question to test your logical and programming knowledge at once.
PS: If X=m and Y=c, the question is simply to tell difference between malloc and calloc

1. `calloc()` zero-initializes the buffer, while `malloc()` leaves the memory uninitialized.

2. The first letter. The number of arugments each takes. Also, calloc zero-values all elements it allocates.

Description:

void *malloc(size_t size);

The function allocates an object of size_t size (size_t = int, char, float...etc), and returns the address of the object if successful; otherwise, it returns a null pointer. The values stored in the object are indeterminate. You can safely convert the return value to an object pointer of any type whose size is not greater than size.

void *calloc(size_t nelem, size_t size);

The function allocates an array object containing nelem (number of elements) each of size_t size, stores zeros in all bytes of the array, and returns the address of the first element of the array if successful; otherwise, it returns a null pointer. You can safely convert the return value to an object pointer of any type whose size in bytes is not greater than size.

Read more on Internet if you like

### Program to remove duplicates in sorted array

This has been asked multiple times at multiple places. In fact, it is one of the Puzzle I had seen at Amazon Interview 2010

Write a program / algorithm to remove duplicates from a sorted array.

PS: You can devise other means. In case, you find your answer to be more efficient, let the community know about that. After posting here , you can personally email me at Toughjamy@Yahoo.com for review.

int remove_duplicates_in_Sorted_Array(int * p, int size)
{
int c, i = 1;
for (c=1; c < size; c++)
if (p[c] != p[i-1])
{
p[i] = p[c];
c++; i++;
else {c++;}
return i;}

### Dog At Same Position : Bear Color Puzzle

Classic Puzzle

If a Dog walks one mile south,
turns left and walks one mile to the east
and then turns left again and walks one mile north
...
And arrives at its original positio.

A. How is it possible
B. If it was not a Dog, but a Bear born and brought up tat the same place, what is the color of the bear.

One Possible point can be exact geographical North Pole
And if it is a bear, it is a polar bear.
So most probably White in Color!!

Important:  In addition to the trivial north pole and circle near north pole solutions, there is an additional circle near south pole solution. Set your mind juices flowing. You will get that answer too!!

## Monday, March 11, 2013

### Facebook Prime Bits Programming Puzzle

We know that, Every Positive integer can be represented using binary. That is, a number can be written in base of 2 also. Like decimal numbers, which is based around powers of ten. For example, 215 is really 2*102 + 1*101 + 5*100. Binary numbers  involves using 2's rather than 10's as place values, so, e.g., 5 is written as 101 = 1*22 + 0*21 + 1*20.

Every integer therefore can be respresented as a string of zeroes and ones. Define P(x) to be true if the number of ones in the binary representation of x is prime and false otherwise.

So, e.g., P(5) is true but P(4) is false.

Our job is to implement the function uint64_t prime_bits(uint64_t a, uint64_t b); which returns the number of integers k, a = k = b such that P(k) is true. uint64_t is a way of designating 64-bit numbers in C/C++.

This has been asked in Facebook. And people wanting to get the solution can email me at Toughjamy@yahoo.com. I do not guarantee to reply to all the emails at once, but will cater to your requests in a batch that I look once every fortnight.

:)

Best is to discuss here..

### Basic Combination Problem 1: Cards

You have a pack of 52 cards:-

1. In how many ways you can take four cards so that 2 of them are Aces and all four of them are Red
2. What is the probabilty that atleast three of them are less than 10

They are easy ones, if you have sound mathematics background. But extremely tough if you have maths phobia. Now prove what you are.