Heap pattern

Task Scheduler

Given task labels and a cooldown n, the same task must run at least n intervals apart. Return the minimum number of intervals (including idles) needed to finish every task. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 621
  • Medium
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

HeapLeetCode 621

Medium

From the first idea to the best one

  1. 01 Greedy · most-frequent-first (max-heap) O(total · log k)O(k) space
  2. 02 Optimized · the math formula O(total)O(k) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Task Scheduler and spot the heap pattern in it
  • Greedy · most-frequent-first (max-heap): O(total · log k) time, O(k) space
  • Optimized · the math formula: O(total) time, O(k) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Heap

See Task Scheduler run, step by step

Sign in and this page opens on the animation, with all 7 Heap problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.