Question: Python solution, please This question is based on the product recommendation system on the online shopping website. Every time you open a product page on

Python solution, please This question is based on the product recommendation systemon the online shopping website. Every time you open a product pageon the website you can see a section "People who viewed thisPython solution, please

This question is based on the product recommendation system on the online shopping website. Every time you open a product page on the website you can see a section "People who viewed this also viewed" Now given a product relationship represented as a graph(adjacent list), find out the largest connected component on this graph. List findRelatedProducts (List> graph) Notice the graph is transitive. Examples Example 1: Input: var arr = [ ["product1", "product2", "product3"], ["product5", "product2"], ["product6", "product7"], ["product8", "product7"] ] Output: ["product1", "product2", "product3", "product5"] Explanation: Output: ["product1", "product2", "product3", "product5"] Explanation: First, we need to process the input and build the graph like this: P1 P2 P3 P5 P6 P5 P6 P7 P7 Here product1 has two recommendations: "product2", "product3" product2 has one recommendation: "products" " Put it together we have the largest recommendation component ["product1", "product2", "product3","products"]. Notice ["product6", "product", "products"] is also a connected component but smaller than the previous one. 1128 PM th) FNG

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!