Pergunta de entrevista da empresa WorldQuant

Find the maximum of two numbers without using if-else or any other comparison operator.

Resposta da entrevista

Sigiloso

19 de mai. de 2018

Let the two numbers be a, b. Calculate the average, m = (a+b)/2. Calculate the standard deviation, sigma = sqrt( ((a-m)^2 + (b-m)^2)/2 ) = |a-b|/2. The maximum is m + sigma.

1