Bird
0
0

Consider a search system that indexes products by category and price. If a user searches with filters category='books' and price < 20, which data structure best supports fast filtering?

medium📝 Analysis Q13 of 15
LLD - Design — Hotel Booking System
Consider a search system that indexes products by category and price. If a user searches with filters category='books' and price < 20, which data structure best supports fast filtering?
AA hash map keyed by category with sorted price lists
BA single unsorted list of all products
CA queue of products ordered by insertion time
DA stack of products sorted by price
Step-by-Step Solution
Solution:
  1. Step 1: Analyze filtering needs

    Filtering by category and price requires quick lookup by category and efficient price range queries.
  2. Step 2: Choose data structure supporting these queries

    A hash map keyed by category allows fast category lookup; sorted price lists enable quick filtering by price.
  3. Final Answer:

    A hash map keyed by category with sorted price lists -> Option A
  4. Quick Check:

    Hash map + sorted list = B [OK]
Quick Trick: Use hash map for categories and sorted lists for range filters [OK]
Common Mistakes:
  • Using unsorted lists causing slow searches
  • Using queue or stack which don't support efficient filtering
  • Ignoring the need for sorting by price

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes