Last active
September 2, 2016 09:41
-
-
Save rohmanhakim/161a63231a92654b887f54630cde9883 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var nkq = ['3','2','3']; | |
var arr = (['1','2','3']).map(function(num) { | |
return parseInt(num); | |
}); | |
var m = ['0','1','2']; | |
var n = parseInt(nkq[0]); | |
var k = parseInt(nkq[1]); | |
var q = parseInt(nkq[2]); | |
var rightRotate = function(arr,k) { | |
return arr.map(function (num,index,arr){ | |
var next = index - (k % arr.length); | |
return arr[next < 0? arr.length + next : next]; | |
}); | |
} | |
rightRotate(arr,k); | |
var getQuery = function(arr,m) { | |
return m.map(function (num,index,m){ | |
return arr[parseInt(m[index])]; | |
}); | |
} | |
console.log(getQuery(rightRotate(arr,k),m).join("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment