Bird
0
0

What will be the output of this pseudocode snippet for assigning agents?

medium📝 Analysis Q5 of 15
LLD - Design — Food Delivery System

What will be the output of this pseudocode snippet for assigning agents?

agents = [Agent1(busy), Agent2(free), Agent3(free)]
AssignAgent(order):
  for agent in agents:
    if agent.status == "free":
      return agent.name
  return "No agent"
print(AssignAgent(order))

AAgent2
BAgent1
CNo agent
DAgent3
Step-by-Step Solution
Solution:
  1. Step 1: Iterate over agents in order

    Agent1 is busy, so skipped. Agent2 is free, so returned immediately.
  2. Step 2: Confirm output

    Function returns Agent2's name on first free agent found.
  3. Final Answer:

    Agent2 -> Option A
  4. Quick Check:

    First free agent = Agent2 [OK]
Quick Trick: Returns first free agent found in list order [OK]
Common Mistakes:
  • Returning busy agent
  • Returning last free agent instead of first
  • Returning "No agent" incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes