Created
August 22, 2020 11:18
-
-
Save yungyungGwon/d487369975608dc2212c8b3e9ae41284 to your computer and use it in GitHub Desktop.
Algorithm
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
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