Bird
0
0

Given the following code snippet, what will be the total quantity of products in the cart after adding 3 units of Product A and 2 units of Product B?

medium📝 Analysis Q4 of 15
LLD - Design — Online Shopping Cart
Given the following code snippet, what will be the total quantity of products in the cart after adding 3 units of Product A and 2 units of Product B?
cart.addProduct(productA, 3);
cart.addProduct(productB, 2);
cart.addProduct(productA, 1);
A3
B6
C5
D4
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total quantity for Product A

    Product A is added twice: 3 + 1 = 4 units.
  2. Step 2: Calculate total quantity for Product B and sum all

    Product B is added once with 2 units. Total quantity = 4 + 2 = 6.
  3. Final Answer:

    Total quantity in cart is 6 -> Option B
  4. Quick Check:

    Total quantity = 6 [OK]
Quick Trick: Sum quantities of same product added multiple times [OK]
Common Mistakes:
  • Ignoring second addition of Product A
  • Adding only last quantity
  • Counting products instead of quantities

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes