Feature #3: Upselling Products
Implementing the "Upselling Products" feature for our "Amazon" project.
We'll cover the following
Description
Amazon wants to upsell related products to the customer during checkout. Amazon wants to do this by recommending a single product picked randomly from a collection of several related products. We must implement three related features to recommend. First, we want to enable adding an item to the list of related products. Second, we want to enable removing an item from the list once it is deprecated. Lastly, we want to enable picking a random item from the list such that any item is equally likely to be picked. We must implement all of these features so that they run in O(1) time.
For this feature, we will keep track of the products by only using their IDs. The insertion, deletion, and retrieval will use the ID of the product. The following illustration shows how products are mapped to IDs:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.