Question:
You have 100 coins, 37 of them are heads, rest are tails. Your task is to divide this 100 coins into two groups in which there will be the same number of heads. You are blindfolded and you can flip any number of coins.
Solution:
Pick any 37 coins and flip all of them.
Explanation:
Lets take a simple case where 5 coins with 3 heads and 2 tails.
HTHHT
Lets take 3 coins randomly. Say first,fouth and fifth lets call it S1. Let remaining coins be S2. So we have 2 groups now
S1(H,H,T) and S2(T,H)
When we flip the selected set S1 it turns into S1F(T,T,H). We have only one head in both the sets.
Categories
FollowersBlog Archive
Jobs
Find more freelance jobs
|
Sunday, November 21, 2010How to select k sample nodes from a unknown sized linked list.?
http://en.wikipedia.org/wiki/Reservoir_sampling can be applied here. Is there any better solution for this problem?
Map reduce implementation of reservoir sampling is discussed in this blog post. http://had00b.blogspot.in/2013/07/random-subset-in-mapreduce.html
Subscribe to:
Posts (Atom)
|
Popular Posts
|