Bird
0
0

Consider this event-driven system snippet:

medium📝 Analysis Q5 of 15
LLD - Advanced LLD Concepts
Consider this event-driven system snippet:
events = []
def add_event(e):
    events.insert(0, e)
def get_event():
    if events:
        return events.pop()
    return None

add_event('X')
add_event('Y')
print(get_event())
print(get_event())

What is the output?
ANone None
BY X
CX Y
DY None
Step-by-Step Solution
Solution:
  1. Step 1: Analyze event insertion

    Events are inserted at the front: first 'X', then 'Y' at front, so list is ['Y', 'X'].
  2. Step 2: Analyze event retrieval

    get_event() pops from end, so first pop returns 'X', second pop returns 'Y'.
  3. Final Answer:

    X Y -> Option C
  4. Quick Check:

    Insert front, pop end = X Y [OK]
Quick Trick: Insert front + pop end reverses order [OK]
Common Mistakes:
  • Assuming pop removes front
  • Confusing insert and append
  • Mixing order of events

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes