Swapping two variables without using third variable

This is a very common interview question, esp. at the junior level. Let us first write a function that swap two integers using a third […]

Prisoners and the lightbulb puzzle

There are 10 prisoners are in 10 different cells of a prison. There is no way in which they can communicate with each other. Each night, […]

Logic Puzzle: Inverting the glasses

Four glasses are placed on the four corners of a square rotating table. Each glass is either upright (up) or upside-down (down). You have to […]

Interview Puzzle: Heaven or Hell

You are standing before two closed doors. One of the doors leads to heaven and the other one leads to hell. Two watchmen are standing, one in front […]

Gold bar puzzle

You have some work to be done by a worker in 7 days. The worker need to be paid every day after his work. The […]

Points on globe – Interview puzzle

How many points are there on the globe, so that if you walk 1km south, then 1km east and then 1km north, you reach the place where you […]

Fastest horse Interview question

There are twenty five horses and you can conduct a race of only five horses at one time. There is no way to find out […]

Count all left nodes in a Binary tree

One way to ask this question is: Given a Binary tree that represent a family hierarchy. A parent can have at most two children (at most […]

5 Pirates Puzzle dividing 1000 coins

There are 5 pirates, A, B, C, D and E. They have a strict hierarchy, A is senior to B, B is senior to C, […]

Cheating Husband puzzle

A certain town has 100 married couples (husband and wife only). Everyone in the town lives by the following rule: If a husband cheats on his wife, […]