# Category Archives: Mathematical

## Check if a number is PalindromeApril 5, 2013

Given an integer, write a function that returns true if the given number is palindrome, else false. For example, 12321 is palindrome, but 1451 is not palindrome.

## Efficient program to print all prime factors of a given numberDecember 28, 2012

Given a number n, write an efficient function to print all prime factors of n. For example, if the input number is 12,

## Measure one litre using two vessels and infinite water supplyDecember 26, 2012

There are two vessels of capacities ‘a’ and ‘b’ respectively. We have infinite water supply. Give an efficient algorithm to make exactly 1 litre of water in one of the vessels.

## Efficient program to calculate e^xDecember 10, 2012

The value of Exponential Function e^x can be expressed using following Taylor Series. e^x = 1 + x/1! + x^2/2! + x^3/3! + ……

## Program to convert a given number to wordsDecember 8, 2012

Write code to convert a given number into words. For example, if “1234” is given as input, output should be “one thousand two hundred thirty four”.

## Program to find amount of water in a given glassDecember 6, 2012

There are some glasses with equal capacity as 1 litre. The glasses are kept as follows:

## Find the largest multiple of 2, 3 and 5November 12, 2012

An array of size n is given. The array contains digits from 0 to 9. Generate the largest number using the digits in the array such that the number is divisible by 2, 3 and 5.

## Select a random number from stream, with O(1) spaceNovember 5, 2012

Given a stream of numbers, generate a random number from the stream. You are allowed to use only O(1) space and the input is in the form of stream, so can’t store the previously seen numbers.

## Pascal’s TriangleNovember 1, 2012

Pascal’s triangle is a triangular array of the binomial coefficients. Write a function that takes an integer value n as input and prints first n lines of the Pascal’s triangle. Following are the first 6 rows of Pascal’s Triangle.

## Significance of Pascal’s IdentityOctober 23, 2012

We know the Pascal’s Identity very well, i.e. ncr = n-1cr + n-1cr-1

## Reservoir SamplingOctober 18, 2012

Reservoir sampling is a family of randomized algorithms for randomly choosing k samples from a list of n items,