Pergunta de entrevista da empresa Meta

Given a function for a fair coin, write a function for a biased coin that returns heads 1/n times (n is a param).

Respostas da entrevista

Sigiloso

26 de mar. de 2010

http://ideainfusion.blogspot.com/2010/01/amazons-biased-coin-toss-problem.html

4

Sigiloso

1 de nov. de 2012

Use flip() 32 times (or 64 or whatever multiple of 32 pleases you) and glue the bits together to form a integer X. Let's say M is the highest multiple of N representable on 32 bits. Do this until X <= M. Now, if X divides by N, return Heads. Otherwise, return Tails.

2

Sigiloso

10 de dez. de 2012

int baisedFlip(h) { int t = h, k = 0; while (t >>= 1) { k = (k h) { return biasedFlip(h); } else if (k == h) { return true; } else { return false; } }

1

Sigiloso

23 de jan. de 2013

int biasedFlip(h){ }

Sigiloso

23 de jan. de 2013

int biasedFlip(int n){ }

Sigiloso

10 de mar. de 2011

@Me you need to use the flip() method Boolean biasedFlip(int i){ Boolean result = true; for (int j=0; j

Sigiloso

22 de jan. de 2010

biasedCoin(int n){ int new = Math.Random()*n; if(new==1) return true } return false }