← 返回 coinbase 的题目列表Priority Queue and Lexicographical Order
类型:online_judge
Implement a priority queue that organizes names in lexicographical order. You need to implement the following functions:
add(name: str) -> None: Adds a name to the queue.
remove() -> str: Removes and returns the name with the highest lexicographical order.
peek() -> str: Returns but does not remove the name with the highest lexicographical order.
is_empty() -> bool: Checks if the queue is empty.
You do not need to consider performance optimization; just implement the basic functionality.
Example:
add("Alice")
add("Bob")
add("Charlie")
remove() -> "Alice"
peek() -> "Bob"
remove() -> "Bob"
remove() -> "Charlie"
is_empty() -> true
Data size: supports up to 10^5 names. Each name's length does not exceed 100 characters.
Example
Input
add Alice
add Bob
add Charlie
remove
peek
remove
remove
is_empty