Last active
January 17, 2016 02:33
-
-
Save rafaelbernard/a7ce7de683c9514dcc41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment