Saturday, November 19, 2011
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly?
Labels:Data
Amazon Interview
Given a string of lowercase characters, reorder them such that the same characters are at least distance d from each other.
Input: { a, b, b }, distance = 2
Output: { b, a, b }
Labels:Data
Google Interview
Thursday, November 17, 2011
Why 11/11/11 Is Mathematically Amazing
You All Know Some Times Back We Had Data 11/11/11, is a once-in-a-century occurrence, adding to a November has been a very fun month for recreational mathematicians.
Last week, a rare eight-digit palindrome date — 11/02/2011, which reads the same frontward and backward — was found to have other mathematical qualities that made it a once-in-10,000-years date.Aziz Inan, a professor of electrical engineering at the University of Portland, Oregon, crunched the numbers and found that when the date was expressed as a number, 11,022,011, it has very special properties.
"It is the product of 7 squared times 11 cubed times 13 squared. That is impressive because those are three consecutive prime numbers. No other palindrome date up to A.D. 10,000 is like that," Inan said. "Not only that, if you write it out as 72 x 113 x 132, you'll notice that even the superscript power numbers — 232 — are a palindrome."
A once-in-10,000-years date is hard to top, but 11/11/11 is no slouch. Some people believe that the date 11/11/11 is a mystical day of good luck, or that 11/11/11 is a good day to make money. Inan explained that when one looks closely at the date, it too has some interesting mathematical properties.
After today, 11/11/11 will next occur 100 years down the road, on Nov. 11, 2111. Interestingly, in 2111, 11/11/11 will be followed by an eight-digit palindrome day, 11/12/2111, which is quite exciting for palindrome fans like Inan.
If you consider today's date as a number — 111,111 — you can run some additional fun math tricks, Inan explained. 111,111 can be obtained from its largest prime number factor, 37, like so: First, subtract 37 from its reverse (73) and you get 36. (Inan added that 36 is equal to the square of the sum of the digits in 111,111.)
Then, split 36 into three consecutive numbers that add up to 36 (11, 12 and 13). Then, multiply 11, 13, 37 and the reverse of 12 (21). And what comes out? You guessed it: 111,111.
Source www.lifeslittlemysteries.com/
Labels:Data
Yahoo Interview
Tuesday, November 15, 2011
Given Table of Cities , Find Minimum Number of Hopes Required to Fly From One to Other City
There is a very Primitive Database and it has a table say "Travel". The content of table is as follows:
Source | Dest
--------------
Sea | LA
LA | FL
LA | MA
FL | Sea
Sea | FL
--------------
Sea | LA
LA | FL
LA | MA
FL | Sea
Sea | FL
The ask is to find out all routes between (Sea) to (FL) with mininum hop.
the Result would be:
1. Sea -> FL
2. Sea -> LA - > FL
the Result would be:
1. Sea -> FL
2. Sea -> LA - > FL
You have to write a Middle tier function to achieve above result. You can assume there is DBAPI that return the Destination city if you provide the source city.
Labels:Data
Amazon Interview
,
DirectI Interview
,
Dynamic Programming
,
Facebook Interview
,
Google Interview
,
Microsoft Interview
,
Recursion
Monday, October 31, 2011
An array is given consisting of real integers , can hav repeatative elements , Now u need to find K partitions whose union will hav all the elements of the array , but the intersection of any pair of cannot hav K elements in common.
Example:-
Array- 1 1 2 2 3 1 4 3 5
For K=3 the partition are :-
(1 2 3) (1 5 2) (1 4 3)
cann't be :- (1 2 3)(3 1 2)(1 4 5)
Array- 1 1 2 2 3 1 4 3 5
For K=3 the partition are :-
(1 2 3) (1 5 2) (1 4 3)
cann't be :- (1 2 3)(3 1 2)(1 4 5)
Suppose u have a square matrix, where every cell is filled with 0 or 1 . U need to find the maximum subsquare such that all four borders are filled with all 1s.
Ex:-
1 0 0 1 1 0
1 0 1 1 1 0
0 0 1 0 1 1
0 1 1 1 1 0
1 0 0 1 1 1
Here the maximum square (3X3) possible is from the TOP LEFT (2 3) TO
BOTTOM RIGHT (4 5) .
1 0 0 1 1 0
1 0 1 1 1 0
0 0 1 0 1 1
0 1 1 1 1 0
1 0 0 1 1 1
Here the maximum square (3X3) possible is from the TOP LEFT (2 3) TO
BOTTOM RIGHT (4 5) .
Thursday, October 20, 2011
Given two bst, print the output that would come if two bsts are merged and then an inorder traversal is performed. Of, course you can't merge trees here.
PS:Heard From One of The My Friend :
Labels:Data
Amazon Interview
,
Google Interview
Subscribe to:
Posts
(
Atom
)