Загрузка...

Leetcode 3408. Design Task Manager | Heap + HashMap | Python Solution

In this video,
We solve Leetcode 3408. Design Task Manager step by step.

💡 Problem:
We need to design a system that:
Initializes with given tasks (userId, taskId, priority).
Supports adding new tasks.
Supports editing a task’s priority.
Supports removing a task.
Executes the top task (highest priority, then smallest taskId).

🔑 Approach:
Use a HashMap (taskId → (priority, userId)) to track the latest state of tasks.
Use a Heap ((-priority, -taskId, userId)) to get the top task efficiently.
On edit and add, push a new tuple into the heap (lazy update).
On rmv, mark the task invalid in the hashmap.
On execTop, pop invalid/old tasks until we find the correct one.

📈 Complexity:
add, edit: O(log n) (heap push)
rmv: O(1) (mark invalid)
execTop: Amortized O(log n) (heap cleanup)
Space: O(n)
This is a classic heap + hashmap lazy deletion design pattern, very useful in system design style problems.

Hashtags:
#Leetcode #Heap #HashMap #DesignProblems #Python #Leetcode3408 #StatlearnTech #CodingInterview

Видео Leetcode 3408. Design Task Manager | Heap + HashMap | Python Solution канала StatLearn Tech
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять