Pergunta de entrevista da empresa Quantcast

write code to find the largest k numbers in an array

Resposta da entrevista

Sigiloso

3 de mar. de 2016

$K = 5; //set K $Ar = array(2,3,4,55,672,1,14,5235,2346,2,2,2645,7698,564,8569,45,478,95547,4,74,47,4,5679,9); //Random Array rsort($Ar); //Sort largest first var_dump(array_slice($Ar, 0, $K)); //Prints only the first K, which will be the largest.

1