반응형
https://programmers.co.kr/learn/courses/30/lessons/42587?language=kotlin
코딩테스트 연습 - 프린터
일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린
programmers.co.kr
data class Document(
val priority: Int,
val isTarget: Boolean
)
class Solution {
fun solution(priorities: IntArray, location: Int): Int {
var answer = 0
val documents = priorities.mapIndexed { idx, priority ->
Document(
priority,
if (location==idx) {
true
} else {
false
}
)
}.toMutableList()
while(true) {
var found:Boolean = false
val firstDocument = documents.removeAt(0)
var highestPriority = firstDocument.priority
documents.forEach { document ->
if (document.priority > highestPriority) {
found = true
return@forEach
}
}
if (found) {
documents.add(firstDocument)
} else {
answer += 1
if (firstDocument.isTarget) {
return answer
}
}
}
}
}
반응형
☕️ Networking
기술 직군의 기술적인 교류, 커리어 이야기, 직군 무관 네트워킹 모두 환영합니다!
위클리 아카데미 오픈 채팅방(비밀번호: 9323)
kakaotalk: https://open.kakao.com/o/gyvuT5Yd