Feature #14: Find Similar Products
Implement the "Find Similar Products" feature for our "Amazon" project.
Description
We want to create a product recommendation system. Product recommendations are an important business function. It’s important and beneficial for a business to recommend the right products to groups of users with similar tastes and interests. To recommend the right products, first, we must find people with similar tastes.
We are given the products that were purchased recently by two users. We want to find how similar their purchases were by finding the products that they both purchased.
Suppose we have 1000
products in total and each user can buy a maximum of 1000
products at a time. Given two lists that represent the products recently bought by the two users, our task is to find all the items that both of them purchased.
Note: We don’t need to fetch an item twice if both the users have purchased it twice.
Let’s look at an example to better understand this:
Note: We will use product IDs, instead of product names, to represent each product.
Solution
To solve this problem, a beginner’s approach will be to iterate along the first array, products_ids1,
and check if each product is present in the products_ids2
array or not. If each of the products is present in the products_ids2
array, we’ll add the product id to the output. This approach will give us ...
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.