-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode Username
Banh Phuc Thinh
Problem Number, Title, and Link
https://leetcode.com/problems/design-task-manager/?envType=daily-question&envId=2025-09-18
Bug Category
Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Bug Description
I have found a test case where my solution will go wrong, but my solution push is correct.
My solution submission is correct, while it went wrong with this testcase.
the test is here
a = TaskManager([[9,5,0],[0,10,0]])
a.rmv(10)
print(a.execTop())
Language Used for Code
Python/Python3
Code used for Submit/Run operation
class Task:
def __init__(self, user_id: int, task_id: int, priority: int):
self.user_id = user_id
self.task_id = task_id
self.priority = priority
def __lt__(self, other):
if self.priority == other.priority:
return self.task_id > other.task_id
return self.priority > other.priority
class TaskManager:
def __init__(self, tasks: list[list[int]]):
self.task_priority_map = defaultdict(int)
self.task_priority_heap = []
self.task_user_map = defaultdict(int)
for user_id, task_id, priority in tasks:
self.task_priority_map[task_id] = priority
self.task_user_map[task_id] = user_id
heapq.heappush(self.task_priority_heap, Task(user_id, task_id, priority))
def add(self, user_id: int, task_id: int, priority: int):
self.task_priority_map[task_id] = priority
self.task_user_map[task_id] = user_id
heapq.heappush(self.task_priority_heap, Task(user_id, task_id, priority))
def edit(self, task_id: int, new_priority: int):
self.task_priority_map[task_id] = new_priority
heapq.heappush(self.task_priority_heap,
Task(user_id=self.task_user_map[task_id], task_id=task_id, priority=new_priority))
def rmv(self, task_id: int):
self.task_priority_map.pop(task_id)
self.task_user_map.pop(task_id)
def execTop(self):
if len(self.task_user_map) == 0:
return -1
highest_priority_task = heapq.heappop(self.task_priority_heap)
while highest_priority_task.priority != self.task_priority_map[highest_priority_task.task_id] or highest_priority_task.user_id != self.task_user_map[highest_priority_task.task_id]:
highest_priority_task = heapq.heappop(self.task_priority_heap)
self.task_priority_map.pop(highest_priority_task.task_id)
self.task_user_map.pop(highest_priority_task.task_id)
return highest_priority_task.user_idExpected behavior
a = TaskManager([[9,5,0],[0,10,0]])
a.rmv(10)
print(a.execTop())
should return 9 but it return 0
Screenshots
No response
Additional context
No response