Bird
0
0

Identify the bug in this emergency alert pseudocode:

medium📝 Analysis Q6 of 15
LLD - Design — Elevator System
Identify the bug in this emergency alert pseudocode:
if sensor.detect() == true
alert.send()
else
alert.send()
ABoth branches send alerts, causing duplicate alerts
BMissing braces cause syntax error
CCondition uses '==' instead of '='
DNo bug, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Analyze conditional branches

    Both 'if' and 'else' branches call alert.send(), so alert is sent regardless of condition.
  2. Step 2: Identify impact

    This causes duplicate alerts for every check, which is a bug in emergency handling.
  3. Final Answer:

    Both branches send alerts, causing duplicate alerts -> Option A
  4. Quick Check:

    Duplicate alerts due to both branches sending = Both branches send alerts, causing duplicate alerts [OK]
Quick Trick: Check if both branches do the same action causing duplicates [OK]
Common Mistakes:
MISTAKES
  • Thinking '==' is assignment
  • Ignoring duplicate alert issue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes