Tuesday, October 26, 2010

How to find nth prime number?.

How to find nth prime number?.

For eg: 15th prime number is 47, ( 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47).

Saturday, October 16, 2010

Generate rand7 from rand5

Initially i though this problem is easy.But it is little difficult.

How to generate rand7() from the given rand5() menthod?

rand7 will generate random numbers between 1..7
rand5 will generate random numbers between 1..5

Url shortener

Write a URL shortner (like tinyurl) . Take a URL as input & return a shortened URL. If you use any kind of storage or persistence, please use the appropriate api's of the language. Another requirement is that we want to make our URLs as different as possible, so that successive calls return very different URIs
This is to ensure that small typo errors do not lead to users getting to a valid URL, but rather throwing up an error page.

Friday, October 8, 2010

Count inversions in unsorted array

Give an unsorted array find count of pairs of numbers[a,b] where a > b and b comes after a in the array.
Eg. {8,3,6,10,5}
the count of such numbers is 5. i.e. (8,3), (8,6), (8,5), (6,5) and (10,5)

Sunday, October 3, 2010

Intersection of two sorted/unsorted arrays

Print the intersection of two arrays given
1. If two arrays are sorted.
2. If two arrays are unsorted.