Skip to content

Instantly share code, notes, and snippets.

@jaredchu
Created March 15, 2018 10:40
Show Gist options
  • Save jaredchu/e5274bc6f16b014aac79963458b6ad37 to your computer and use it in GitHub Desktop.
Save jaredchu/e5274bc6f16b014aac79963458b6ad37 to your computer and use it in GitHub Desktop.
<?php
$handle = fopen ("php://stdin","r");
fscanf($handle,"%d %d",$n,$k);
$a_temp = fgets($handle);
$a = explode(" ",$a_temp);
array_walk($a,'intval');
function rotate_left($arr, $k){
$left = array_reverse(array_slice($arr,0,$k));
$right = array_reverse(array_slice($arr,$k,count($arr)));
return array_reverse(array_merge($left,$right));
}
echo(implode( ' ',rotate_left($a,$k)));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment