Created
March 3, 2017 03:12
-
-
Save torpedo87/e104a71dcb866f568b4eeea907a8a660 to your computer and use it in GitHub Desktop.
[left rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation)
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
##[left rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation) | |
```javascript | |
function main() { | |
var n_temp = readLine().split(' '); | |
var n = parseInt(n_temp[0]); | |
var k = parseInt(n_temp[1]); | |
a = readLine().split(' '); | |
a = a.map(Number); | |
var arr=[1,2,3,4,5] | |
function rotate(arr){ | |
arr.splice(n,0,arr[0]); | |
arr.splice(0,1); | |
} | |
for(var i=0; i<k; i++){ | |
rotate(a); | |
} | |
console.log(a.join(" ")); | |
} | |
``` | |
*** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment