Saturday, October 27, 2012
Thursday, October 25, 2012
Given a positive integer N, arrange the integers 1 to N such the position of the average of two numbers (if present) falls outside the two numbers. For example, for a[i] and a[j], if b = (a[i] + a[j])/2, then if a[k] = b, k < i or k > j. Hint :- If the average of two numbers is not an integer then we can assume that they do not have an average.
One possible solution i can think of is divide the array in two parts , odd and even , sort them and use be.low algo , like if we have the array say N=10 and array is 3 10 2 7 5 3 4 6 9 8 1 after dividing and sorting
array will be 1 3 5 7 9 2 4 6 8 10
now calculate length of even and odd list ,if length is odd,then divide it into 2 equal parts and align alone one middle value like
1 3 5 7 9 2 4 6 8 10
now swap all values of two list except first value based on middle if each sub-list
1 7 5 3 9 2 8 6 4 10
i have not coded it yet so feel free to comment if it fails for any test case :)
Labels:Data
Google Interview
Friday, October 12, 2012
Design a system where you can reutrn top 20 queries made in last 24 hours to users. Think on the scale of Google and Yahoo. How would you store data. What will be your data structures, algorithm to get that data.Describe your assumptions etc. For simplicity, you can assume that every web server create a log file with query and timestamp.
Labels:Data
Google Interview
A legend among a group of n people is a person who is top rated in all respects.The task is to identify a legend by asking a single question of the form "who deserves it?" Design an efficient algorithm to identify a legend or determine if the group has no such person.How many questions does your algorithm need in the worst case??
Labels:Data
Amazon Interview
Wednesday, October 3, 2012
Sunday, September 30, 2012
While travelling in a cycle race, there are several pit stops. A cyclist can travel upto 50 km without stopping at any pit stop, where he can have a health drink and refill his energy. Given a start point ’t’ and let ’k’ be the distance needed to be travelled by the cyclist, find an efficient algorithm to reach the destination ’d’ so as to have minimum pit stops and prove your algorithm is the most optimal one.
Labels:Data
Microsoft Interview
You have given n numbers from 1 to n. You have to sort numbers with increasing number of set bits.
for ex: n=5.
output: 1,2,4,3,5
Note: If you have two number with equal number of set bits, then number with lowest value come first in the output.
output: 1,2,4,3,5
Note: If you have two number with equal number of set bits, then number with lowest value come first in the output.
Labels:Data
Microsoft Interview
Wednesday, September 26, 2012
Subscribe to:
Posts
(
Atom
)