# Math Puzzles

## Number of Trailing Zeros in Factorial of a Number

Write a program to output the number of consecutive trailing zeros in the factorial of a number? Solution: 1. The number of trailing zeros in a number is equivalent to the power of 10 in the factor of that number. 2. The number power of 10 in the factors is the same as the minimum Read More →

## Possible Paths across a Rectangular Grid

Problem: Consider a rectangular grid of 4×3 with lower  left corner named as A and upper right corner named B. Suppose that starting point is A and you can move one step up(U) or one step right(R) only. This is continued until B is reached. How many different paths from A to B possible ? Now let’s Read More →

## Handshake Problem

Problem: At a party, everyone shook hands with everybody else. There were 66 handshakes. How many people were at the party? This question is asked in Infosys written. Solution: Lets say there are n persons 1st person shakes hand with everyone else: n-1 times(n-1 persons) 2nd person shakes hand with everyone else(not with 1st as Read More →

## Riding Against the Wind Puzzle

Problem: A horse rider went a mile in 5 minutes with the wind and returned in 7 minutes against the wind. How fast could he ride a mile if there was no wind? Solution: Most of us will proceed like that if a rider goes a mile in 2 minutes with the wind, and returns Read More →

## Probability of getting one rupee coin from bag

Problem: A bag contains (x) one rupee coins and (y) 50 paise coins. One coin is taken from the bag and put away. If a coin is now taken at random from the bag, what is the probability that it is a one rupee coin? Answers: Case I: Let the first coin removed be one Read More →

## Probability of picking 2 socks of same color

Problem: There are 6 pairs of black socks and 6 pairs of white socks.What is the probability to pick a pair of black or white socks when 2 socks are selected randomly in darkness. This question was asked in Aamaon. Solution: Ways to pick any 2 socks from 24 socks = 24C2 Ways to pick Read More →

## Age of 3 children – Mathematical Puzzle

Problem: Two old friends, Jack and Bill, meet after a long time. Jack: Hey, how are you man? Bill: Not bad, got married and I have three kids now. Jack: That’s awesome. How old are they? Bill: The product of their ages is 72 and the sum of their ages is the same as your Read More →

## Red and Blue Marbles Puzzle

Puzzle: You have two jars, 50 red marbles and 50 blue marbles. You need to place all the marbles into the jars such that when you blindly pick one marble out of one jar, you maximize the chances that it will be red. When picking, you’ll first randomly pick a jar, and then randomly pick Read More →

## Squares on a chess board?

Problem: How many squares are on a chess board? If you thought the answer is 64, think again! How about all the squares that are formed by combining smaller squares on the chess board (2×2, 3×3, 4×4 squares and so on)? A 1×1 square can be placed on the chess board in 8 horizontal and 8 Read More →

## Generate integer from 1-8 with equal probability

Problem: Write a method to generate a random number between 1 and 8, given a method that generates a random number between 1 and 3. The distribution between each of the numbers must be uniform. Solution: Let’s think of this like a decision tree. Each rand3() will be a decision. If we somehow generate integers Read More →

## Find missing number and duplicate number

Given an array of size N containing number from 1 to n,except one number is missing and one number is duplicated.Find Both numbers in linear time. This problem is an extension of our post of finding missing number in an array. Solution : Let missing number be x and duplicate number be y. We know Read More →

## 3 Doors and Heaven

Problem: A person dies, and he arrives at the gate to heaven. There are 3 doors in the heaven. One of the door leads to heaven, second one leads to a 1-day stay at hell and then back to the gate and the third one leads to a 2 day stay at hell and then Read More →