Unit 4 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
Q: What is the structure of the input?
Q: What is the output?
Q: How should the function handle the order of NFTs?
Q: Are there any constraints on the input list?
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Use a queue to process NFTs in the order they were added. Dequeue each NFT and add its name to the final processing order.
1) Initialize an empty list called `processing_order` to store the names of NFTs in the order they are processed.
2) Convert `nft_queue` into a deque to facilitate FIFO operations.
3) While the `queue` is not empty:
a) Dequeue the first NFT from the queue.
b) Append the NFT's name to `processing_order`.
4) Return the `processing_order` list.
**⚠️ Common Mistakes**
- Forgetting to use the correct data structure (queue) to maintain the FIFO order.
- Misunderstanding the role of processing time in determining the order (processing time does not affect the order in this problem).
from collections import deque
def process_nft_queue(nft_queue):
processing_order = []
queue = deque(nft_queue) # Initialize the queue
while queue:
nft = queue.popleft() # Dequeue the first NFT
processing_order.append(nft["name"])
return processing_order