Sort the array with 0s and 1s

You are given an Array of N size. It contains 0s and 1s only. You have to arrange all 0s before all 1s and you are not allowed to travel more than once through the array.

Find a cycle in a linked list..

How would you find a cycle in a linked list?

Store all receiving samples..

Given that you are receiving samples from an instrument at a constant rate, and you have constant storage space, how would you design a storage algorithm that would allow me to get a representative readout of data, no matter when I looked at it? In other words, representative of the behavior of the system to date.

Multiply by 7..

Multiple by 8 without using multiplication or addition. Now do the same with 7.

Count number of 1s..

Count the number of set bits in a number. Now optimize for speed. Now optimize for size.

Circular linked list..

Implement an algorithm to insert a node into a circular linked list without traversing it.

Find ratio..

If you have two buckets, one with red paint and the other with blue paint, and you take one cup from the blue bucket and poor it into the red bucket. Then you take one cup from the red bucket and poor it into the blue bucket. Which bucket has the highest ratio between red and blue? Prove it mathematically.

Measure exactly 4 quarts..

If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?

Break the gold bar..

You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker?

Minimum attempts..

You have a bucket of jelly beans. Some are red, some are blue, and some green. With your eyes closed, pick out 2 of a like color. How many do you have to grab to be sure you have 2 of the same?

Find odd jar...

You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just one measurement?

Why is a manhole cover round?

Why is a manhole cover round?

Minimum number of weighings..

You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?

Now, Assume that we don't know whether the odd ball is heavier or lighter. Find the number of minimum number of weighings required to find the odd ball.

Check the above two conditions when the number of balls are 12.

Proportion of boys to girls..

In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?

100 married couples

Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announce that at least one husband has been unfaithful. What happens?

Cutting rectangular cake

How do you cut a rectangular cake into two equal pieces when someone has already taken a rectangular piece from it? The removed piece an be any size or at any place in the cake. You are only allowed one straight cut.

Car accident

A father and son are in a car accident. The father dies instantly, and the son is taken to the nearest hospital. The doctor comes in and exlaims "I can't operate on this boy."

"Why not?" the nurse asks.

"Because he's my son," the doctor responds.

How is this possible?


Note: The boy does't have two fathers

Sort with mininum comparisions..

Can we sort 5 given elements with 7 comparisons?

Match switch with its bulb..

There is a room with a door (closed) and three light bulbs. Outside the room there are three switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can't change them. Identify each switch with its bulb?

Measure 4 quarts..

If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?

Cross the bridge

There are 4 women who want to cross a bridge. They all begin on the same side. You have 17 minutes to get all of them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. The flashlight must be walked back and forth, it cannot be thrown, etc. Each woman walks at a different speed. A pair must walk together at the rate of the slower woman's pace.

Woman 1: 1 minute to cross
Woman 2: 2 minutes to cross
Woman 3: 5 minutes to cross
Woman 4: 10 minutes to cross

For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes? Now, what's the other way?

Find ages ?

Two MIT math graduates bump into each other. They hadn?t seen each other in over 20 years.

The first grad says to the second: ?how have you been??

Second: ?Great! I got married and I have three daughters now?

First: ?Really? how old are they??

Second: ?Well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there..?

First: ?Right, ok.. oh wait.. I still don?t know?

second: ?Oh sorry, the oldest one just started to play the piano?

First: ?Wonderful! my oldest is the same age!?

Problem: How old are the daughters?