Skip to content

Instantly share code, notes, and snippets.

@yungyungGwon
Created August 22, 2020 11:18
Show Gist options
  • Save yungyungGwon/d487369975608dc2212c8b3e9ae41284 to your computer and use it in GitHub Desktop.
Save yungyungGwon/d487369975608dc2212c8b3e9ae41284 to your computer and use it in GitHub Desktop.
Algorithm
function solution(priorities, location){
var answer = 1;
var first = -1;
var requestIdx = location;
while(priorities.length > 0){
first = priorities.shift();
if(priorities.some((value, index) => value > first)){
priorities.push(first);
}
else{
if(requestIdx == 0){
break;
}
else{
answer++;
}
}
if(requestIdx == 0){
requestIdx = priorities.length - 1;
}
else{
requestIdx--;
}
}
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment