Amazon VO 面试真题解析:购物车促销筛选设计题(Cart / Item)

16次阅读
没有评论

You’re working at Amazon retail and you’re in charge of implementing a method/function to be used by the promotions team to apply a discount to each individual item in the checkout cart.

The function is used to find items that meet a certain promotion criteria.

There are currently two ongoing promotions. The criteria for each promotion is as follows:

  • Items in the cart that are a certain price (e.g. > $20).
  • Items in the cart that belong to a certain product group. Product groups can be (Clothes, Hardware, Media, Toy, Food).

Given this information:

  • Design the Cart and Item classes.
  • Create the method/function that will find the items for each of the use cases above.

这是一道典型的 Amazon 面试设计题,核心是围绕购物车促销规则来建模。题目要求先设计 Cart 和 Item 两个类,再实现一个筛选方法,分别支持“按价格阈值筛选商品”和“按商品分组筛选商品”两类条件。解题时通常会把商品价格、品类等属性封装进 Item,把商品集合封装进 Cart,然后通过遍历、条件判断或更通用的过滤接口返回满足促销条件的商品列表。重点考察的是面向对象设计、类职责拆分,以及如何把未来可能扩展的促销规则写得更灵活。

正文完
 0