Satyam Interview Question


Perhaps you have heard that when Microsoft interviews potential employees, the ask them a series of mind-benders. Having recently experienced a Microsoft interview, let me assure you the rumors are indeed true. Here are some of the questions that the four of us were asked when interviewed by MS:

? You are given a scale which you are to use to measure eight balls. Seven of these balls have the same weight: the eigth ball is heavier than the rest. The scale does not indicate the weight of a particular object; it is a scale which tells you which of the two sides being weighed is heavier (like the scale that lady of justice statue holds up). So, for example you could place one ball on each end of the scale. If ball one was heavier than ball two, it would tip in ball one's direction; if ball two were heavier, it would tip io ball three's direction; if the balls were of equal weight, the scale would not tip at all.

What is the minimum number of weighs you could perform to find the heaviest of the eight balls?  

Answer: You can do this in 2 weighs. Put three balls on each side of the scale. That's a total of six balls you're weighing. If the three balls on each side weigh equally, you know that one of the two remaining balls is the heaviest. Weigh those two balls to determine which one is heaviest. If, however, one of the three ball combinations weighs most, remove all balls from the scale, then weigh just two of the three "heavier" balls. If those two balls are equal weight, the third, unweighed ball is the heaviest; otherwise the scale will indicate which of the two balls on the scale is the heavy one.

? Imagine, now, that you have seven balls of unknown weight, given that six are of the same weight, and the seventh is heavier than the rest. Using the same scale as described above,

what is the minimum number of weights you could perform to find the heaviest of the seven balls?

? Imagine that you have 26 constants, labelled A through Z. Each constant is assigned a value in the following way: A = 1; the rest of the values equal their position in the alphabet (B corresponds to the second position so it equals 2, C = 3, etc.) raised to the power of the preceeding constant value. So, B = 2 ^ (A's value), or B = 2^1 = 2. C = 3^2 = 9. D = 4^9, etc., etc. Find the exact numerical value to the following equation:

      (X - A) * (X - B) * (X - C) * ... * (X - Y) * (X - Z) 

Answer: Well, since we have a series of products here, X - X will soon be reached, which will equate to zero. Throwing zero into a product results in an answer of zero. So, the answer is zero. Easy, eh? :)

? Write C code to implement atoi

? And fimally, the hum-dinger: There are four people who need to cross a bridge at night. The bridge is only wide enough for two people to cross at once. There is only one flashlight for the entire group. When two people cross, they must cross at the slower member's speed. All four people must cross the bridge in 17 minutes, since the bridge will collapse in exactly that amount of time. Here are the times each member takes to cross the bridge:

?          Person A: 1 minute

?          Person B: 2 minutes

?          Person C: 5 minutes

google_ad_client = "pub-0219261000974819";google_ad_width = 300;google_ad_height = 250;google_ad_format = "300x250_as";google_ad_type = "text_image";google_ad_channel ="4817331469";google_color_border = ["A8DDA0","DDB7BA","FF4500","CCCCCC"];google_color_bg = ["EBFFED","FFF5F6","FFEBCD","FFFFFF"];google_color_link = ["0000CC","0000CC","DE7008","000000"];google_color_url = ["008000","008000","E0AD12","666666"];google_color_text = ["6F6F6F","6F6F6F","8B4513","333333"];  

 

So, if Person A and C crossed the bridge initally, 5 minutes would elapse, because Person C takes 5 minutes to cross. Then, Person A would have to come back to the other side of the bridge, taking another minue, or six minutes total. Now, if Person A and D crossed the bridge next, it would take them 10 minutes, totalling to 16 minutes. If A came back, it would take yet another minute, totally 17... the bridge would collapse with A and B on the wrong side. How can all four people get across the bridge within 17 minutes? 

Note: there is no trick-answer to this problem. You can't do tricky stuff like throwing the flashlight back from one end of the bridge to the other. This problem can be solved!

# Answer:
# A and B cross together. Total Time: 2 Minutes
# A comes back. Total Time: 3 Minutes
# C and D cross together. Total Time: 13 Minutes
# B comes back. Total Time: 15 Minutes
# A and B cross together. Total Time: 17 Minutes

Recent article: Satyam Question
There are approx. 8 billion search terms per log file (320 GIG / 40 Bytes). Each computer can return it's top 1 million search terms to a central server at a cost of 48MB each because 40 Bytes * 1 million = 40MB, plus a 8 byte unsigned integer occurrence count for each search term. The combined top 1 million results from each log take only 520 MB, so there is plenty of space on any single computer to merge the 12 million entries together and come up with top 1 million. So, the only missing part at this point is how to efficiently count the search term occurrences on each computer, and return the top 1 million (this same algorithm can be used for merging the 12 top 1 million, too). A hash table may be a bad idea. With this many search terms and only 4GIG of memory, hashing the search terms would cause a lot of collisions. You want to use a tree, not a hash. Order ln(n) should work well for the search term lookups (if it's good enough for the STL maps, it's good enough for me, right??!!). Now, we know that we need to produce the top 1 million results,