We have so far solved a few algorithmic/coding problems asked in programming interviews across some of the best companies in the world. Today we are introducing a new series solving Data Science interview questions at these same companies. Many of these places do not have a specialized role for Data Scientists (although that’s changing rapidly). For the rest, a Data Scientist typically solves a logical/mathematical puzzle on a whiteboard. Few of these interviews also ask deep/technical questions on SQL. The rest of the interviews are almost identical to the algorithmic/coding interviews that we have seen so far in this blog. Today, we will solve three simple problems asked at Facebook for a Data Science role. Read along…

Problem 1:

Three ants are sitting at the corners of an equilateral triangle. Each ant randomly picks a direction and starts moving along the edge of the triangle. What is the probability that none of the ants collide? Now, what if it is k ants on all k corners of an equilateral polygon?

Solution

Let’s start simple, shall we? Here are two ways of solving this problem, both should be obvious after a little thought:

  1. How many ways can an ant (at any vertex) move? Precisely two!. All the movements of all three ants are independent are each other. As a result, the total number of movements for all three ants is equal to 2³= 8. How many of these movements result in no-collision? Again, precisely two! (1) All ants moving clockwise, and (2) all ants moving counter-clockwise. As a result, the probability of no collision is simply 2/8 = 0.25. How about k ants? There are again two ways a single ant can move, and hence, k ants can move in 2ᵏ different ways. Just like in the case of a triangle, there are precisely two movements resulting in non-collisions. Again, (1) All ants moving clockwise, and (2) all ants moving counter-clockwise. As a result, the probability of non-collision is simply 1/(2ᵏ-¹).
  2. The above method was frequency counting, where you count the number of ways the event of interest occurs, and divide it by the total number of ways. Let’s directly calculate the probability of non-collision by calculating the probabilities of two independent and mutually exclusive events.

#facebook #software-development #data-science #probability #interview-que

Ants, Dice and Bayes Theorem
1.30 GEEK