Categorias
PHP

Codility – CyclicRotation

I scored 100% in #php on @Codility!
https://codility.com/demo/take-sample-test/cyclic_rotation/

100% de aproveitamento!

<?php
// you can write to stdout for debugging purposes, e.g.
// print "this is a debug message\n";
function solution($A, $K) {
// write your code in PHP5.5
$count = count($A);
$length_offset = $count - $K;
if ($length_offset < 0) {
$quo = intval($K / $count);
$over = $quo * $count;
$length_offset = $count - ($K - $over);
}
$sufix = array_slice($A, 0, $length_offset);
$prefix = array_slice($A, $length_offset);
return array_merge($prefix, $sufix);
}

Deixe uma resposta

Este site utiliza o Akismet para reduzir spam. Saiba como seus dados em comentários são processados.