Pergunta de entrevista da empresa Two Sigma

Two questions for the coding test, one involving pure coding and the other involving some data analysis.