Programming phone screen questions

kSquared at GameDev community forums posted a list of phone screen questions from Google, with some answers that he attempted. You’ll have to head to GameDev to read the answers, but here’s the list of questions to ponder:

  1. You are shrunk to the height of a nickel and your mass is proportionally reduced so as to maintain your original density. You are then thrown into an empty glass blender. The blades will start moving in 60 seconds. What do you do?
  2. How would you find out if a machine’s stack grows up or down in memory?
  3. Explain a database in three sentences to your eight-year-old nephew.
  4. How many gas stations would you say there are in the United States?
  5. How many golf balls can fit in a school bus?
  6. How much should you charge to wash all the windows in San Francisco?
  7. How many times a day does a clock’s hands overlap?
  8. How many piano tuners are there in the entire world?
  9. You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?
  10. You have five pirates, ranked from 5 to 1 in descending order. The top pirate has the right to propose how 100 gold coins should be divided among them. But the others get to vote on his plan, and if fewer than half agree with him, he gets killed. How should he allocate the gold in order to maximize his share but live to enjoy it? (Hint: One pirate ends up with 98 percent of the gold.)
  11. You have to get from point A to point B. You don’t know if you can get there. What would you do?
  12. Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?
  13. Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announces that at least one husband has been unfaithful. What happens?
  14. In a country in which people only want boys, every family continues to have children until they have a boy. if they have a girl, they have another child. if they have a boy, they stop. what is the proportion of boys to girls in the country?
  15. If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?
  16. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands?
This entry was posted in Database, General, Puzzles. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

18 Comments on Programming phone screen questions

  1. Tyson
    Posted 8/21/2008 at 12:50 am | Permalink

    9) You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?

    ANSWER: Weigh 3 balls on each side of balance.
    IF even, the remaining ball is heaviest.
    ELSE, one side will be heavier. Thus the heaviest ball is one of the those three.
    Balance 2 of remaining 3.
    IF even, remaining ball is heaviest.

  2. Tanj
    Posted 8/26/2008 at 9:42 pm | Permalink

    Slight edit on Tyson’s answer

    9) You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?

    ANSWER: Weigh 3 balls on each side of balance.
    IF even, weigh the remaining 2 balls.
    ELSE, one side will be heavier. Thus the heaviest ball is one of the those three.
    Balance 2 of remaining 3.
    IF even, remaining ball is heaviest.

  3. K3V1N
    Posted 8/27/2008 at 7:55 pm | Permalink

    #1. Stay low, depending on the blender of course.

    #7 At least 24 times as every hour has a corresponding minute of overlap.

    #16 0 or 360 degrees.

  4. juju
    Posted 8/28/2008 at 4:27 am | Permalink

    >>ANSWER: Weigh 3 balls on each side of balance. IF even, the remaining ball is heaviest.<<

    Wrong. There are 8 balls, not seven.

  5. juju
    Posted 8/28/2008 at 4:34 am | Permalink

    16. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands?

    —-

    7.5 degrees.

    minute hand is on the 3, hour hand is 1/4 of the way from 3 to 4. Circle is split up into 12 hour sectors, and 12*4=48 quarter hour sectors. The angle is one quarter hour sector, so 360 degrees/48 = 7.5 degrees.

  6. Techno
    Posted 9/9/2008 at 10:56 pm | Permalink

    7. How many times a day does a clock’s hands overlap?

    Ans: A clock’s hand will overlap once in an hour. So in a day = 24 times will get overlap.

    —————

    9. You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you find the ball that is heavier by using a balance and only two weighings?

    Ans: Step-1: First group the balls in 3+3+1
    Step-2: Then take the 3+3 use the first chance to weigh the both set of 3 by placing the weight balancing gauge.

    Suppose if it balanced. The one which we have separately is the heavier.

    Else

    Steup-3: Find the heavier side of 3 balls among them (which is in the weighing gauge) split those as 1+1+1. Then use the second chance to weigh it by using weight balance.
    Keep one ball in each side of the weight balance and keep the other one separately.
    If the weight balance is equal. then heavier is the ball which we have separately or the weight balance will show the heaviest easily.

    ———————–

    16. If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands?

    Ans: While the minute hand is on the 3, hour hand is 1/4 of the way from 3 to 4. That is exactly it might reached one fourth of the distance.

    As the clock is having 360 degrees in total.
    We can find by dividing 360/12 = 30 degrees. That is 30 degree will be the in-between degrees of subsequent hours. (eg: 1-2 will have 30 degree angle)

    Hence to find the 3hrs 15 min degree = 30/4 = 7.5 degree (in 1 hour four 15 min will come right ?)

    7.5 degree will be the ans.

  7. Steve
    Posted 10/3/2008 at 8:56 pm | Permalink

    If the probability of observing a car in 30 minutes on a highway is 0.95, what is the probability of observing a car in 10 minutes (assuming constant default probability)?

    We have a 5% probability of not observing a car in 30 minutes. This is the same as the probability of not observing a car in 10 minutes for 3 consecutive periods. Therefore

    1/20 = (x)^3 where x is the probability of not seeing a car in 10 minutes. Therefore x is approximately 2.714.

  8. fixen
    Posted 10/9/2008 at 3:09 am | Permalink

    For some of the more poignant questions, here’s how I’ll ask the interviewer back:

    1) Will I blend? (if not, lie really flat and pray to as many gods as possible in 60 seconds)

    2) Do I have gdb?

    7) Does the clock have a second hand?

    11) Is this not urgent or does point B save me from a falling piano?

    12) Is there an even distribution of colors or am I as I’m imagining with lots of black shirts? If so, this is obviously a max heap.

  9. fixen
    Posted 10/9/2008 at 3:23 am | Permalink

    Now for #13,

    All 100 couples stand there and look at each other. If there’s one cheater, then there is one wife who can’t see a cheating husband…which means it’s hers. He immediately dies and all is well.

    If nobody says anything that day, then there must be more than one cheater. Assume that there are two, then every wife but one must see two cheating husbands. The wife that sees only one can figure that his husband must be a cheater, because otherwise that one she sees would have died already. She goes stabby, we then go back to the one-cheater scenario, and all is well.

    Assume that there are three cheaters, then everybody but one wife sees three cheaters. When that wife notices that nobody has said anything beyond the time it takes to process the two-cheater scenario (say one more day) she will know that her husband is cheating.

    And so on until all cheaters die.

  10. murali
    Posted 10/13/2008 at 6:10 am | Permalink

    Weigh 3 balls on each side of balance.
    IF even, weigh the remaining 2 balls.
    ELSE, one side will be heavier. Thus the heaviest ball is one of the those three.
    Balance 2 of remaining 3.
    IF even, remaining ball is heaviest.

  11. dixson
    Posted 12/1/2008 at 3:06 am | Permalink

    How many golf balls can fit in a school bus? It depends on the size of the bus,it may be a double decker bus.

    If you look at a clock and the time is 3:15, what is the angle between the hour and the minute hands?
    Sorry,I am wearing a digital watch.

  12. Kaitain
    Posted 12/3/2008 at 5:09 am | Permalink

    #15

    Steve said:
    “1/20 = (x)^3 where x is the probability of not seeing a car in 10 minutes. Therefore x is approximately 2.714.”

    You got your reasoning right but for some reason bungled the final part. x is approximately 0.37, and as this represents the chance of NOT seeing a car in any given ten minute period, the chance of SEEING a car is 0.63 approx.

  13. Kaitain
    Posted 12/3/2008 at 5:14 am | Permalink

    #7

    Techno says:

    “Ans: A clock’s hand will overlap once in an hour. So in a day = 24 times will get overlap.”

    No. Consider a 12 hour rotation, and let’s consider all moments when we move from non-overlapping to overlapping. On the first hour, this DOES NOT OCCUR. On all subsequent hours, it happens once in that hour. (On the twelfth hour, it happens right at the very last second.) So you get 11 overlaps in any twelve hour period, and 22 overlaps in a day.

  14. Nathaniel
    Posted 12/8/2008 at 12:08 pm | Permalink

    #13

    there are 100 cheaters. The wives know of 99. they wake up in the morning no man is dead => their husband is the cheater, so they kill him. All men are dead RIP. (it’s a livelock-like question, it depends on the sampling method)

  15. Posted 12/9/2008 at 12:01 pm | Permalink

    7. A clock’s hands overlap at 12:00, they also overlap once per hour, except in the 11th hour. In the 11th hour, the minute hand doesn’t catch up to the hour hand until 12:00, so the answer is 22 times per day.

  16. Posted 12/9/2008 at 12:11 pm | Permalink

    13. All the men in the village will be killed. Let’s call one of the women #49. She knows of 49 infidelities. If her husband was faithful, all other women would know of 48 infidelities. Now a new woman #48 would assume her husband was faithful and believe all other women knew of 47 infidelities. This would continue until one woman was totally unaware of cheaters. (Keep in mind, all women actually know of 49 cheaters, they just think there is a 49,48,47…1,0 knowledge pattern). When the queen makes her announcement, the lack of surprise in the village will confirm that this pattern is not true, therefore every husband is a cheater and they will all die.

  17. rohit
    Posted 2/6/2009 at 9:21 am | Permalink

    3)A database is like a large book contain everything you needed.

  18. Rohit Jha
    Posted 2/6/2009 at 9:34 am | Permalink

    4) No. of gas station=2*total no. of cities.

    5)No. of Golf ball=(Size of Bus/size of ball)

    6)No.of glass* $1

    7)24

    8)NO.of company making piano tuners*AVG. no. of piano tuners made by them

    9)Total no. of Ball=8
    Weight 3 balls on each side of balance.
    So that one condition comes that they are in equal Weight.
    afterthat 2 ball remaining with 1 weight slightly more.
    Now it is easy to find the heaviest ball.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*