DSA Section簡単

Circular Queue

Detailed guide and Python implementation for the 'Circular Queue' problem.

問題提起

簡単

Write a function execute_circular_queue(size, operations) that simulates a Circular Queue of maximum size size. The input is an integer size and a list of tuples operations of the form ("enqueue", val) or ("dequeue",). If enqueue succeeds, return True, otherwise False. If dequeue succeeds, return the dequeued value, otherwise None.

制約
  • 1 <= size <= 100
  • 0 <= len(operations) <= 1000

Example 1
Input
size = 3, operations = [("enqueue", 1), ("enqueue", 2), ("enqueue", 3), ("enqueue", 4), ("dequeue",)]
Output
[True, True, True, False, 1]
Explanation

Enqueue 1, 2, 3 succeed. Enqueue 4 fails because queue is full. Dequeue returns 1.

Need a Hint?
Consider using Queues-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

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 リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。