상위 150개 인터뷰쉬움

작업 스케줄러

'작업 스케줄러' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

CPU 작업 배열이 제공되며, 각 작업은 A부터 Z까지의 문자와 냉각 간격 n으로 표시됩니다. 각 주기 또는 간격을 통해 하나의 작업을 완료할 수 있습니다. 작업은 어떤 순서로든 완료할 수 있지만 제약이 있습니다. 즉, 냉각 요구 사항으로 인해 동일한 작업을 최소한 n 간격으로 분리해야 합니다.

모든 작업을 완료하는 데 필요한 최소 간격 수를 반환합니다.

leastInterval(tasks: List[str], n: int) -> int 함수를 작성하세요.

제약
  • 1 <= len(tasks) <= 10^4
  • tasks[i] is an uppercase English letter
  • 0 <= n <= 100

Example 1
Input
tasks = ["A","A","A","B","B","B"], n = 2
Output
8
Explanation

A possible sequence is A -> B -> idle -> A -> B -> idle -> A -> B.

Example 2
Input
tasks = ["A","A","A","B","B","B"], n = 0
Output
6
Explanation

With no cooling interval, tasks can be executed continuously without idles.

Need a Hint?
세트나 힙과 같은 힙/우선순위 큐 관련 데이터 구조를 사용하는 것을 고려해보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.