Apple Interview Coding Question: Print All Possible Product Combinations Within a Budget

20 Views
No Comments

Problem 1: Given a budget of $3000 dollars to buy Apple products, create an algorithm to print all possible combinations of products you can buy.

Given the following product categories, each combination should contain one product from each category.

MacBooks:

  • MacBook Air – $1249
  • MacBook Pro 13 Inch – $1399
  • MacBook Pro 15 Inch – $2299
  • MacPro – $5999

iPads:

  • iPad Pro – $1299
  • iPad Air – $729
  • iPad – $459

iPhone:

  • iPhone 14 Pro – $1299
  • iPhone 12 – $799
  • iPhone 14 – $699
  • iPhone 12 Pro Max – $1499

Apple Watch:

  • Apple Watch Nike – $499
  • Apple Watch Hermes – $1099
  • Apple Watch Series 6 – $499

AirPods:

  • AirPods Pro – $299
  • AirPods – $149
  • AirPods Max – $549

Print all valid combinations whose total cost is within the budget.

This problem is a combination enumeration task: choose exactly one item from each Apple product category, and print every bundle whose total cost stays within the $3000 budget. A standard solution uses backtracking or layered iteration, adding one category at a time while maintaining the running total and pruning any branch that already exceeds the budget. The key challenge is to generate all valid cross-category combinations efficiently and avoid exploring impossible bundles.

END
 0