Katkat

Find top co-viewed products

eBaySoftware Engineer · Onsite

Last updated

This question evaluates algorithmic problem-solving and implementation skills in the Coding & Algorithms domain, including frequency aggregation, ordering with tie-breakers, and efficient data-structure use for session-based recommendation counting.

You are given a list of user browsing sessions, where each session is a list of product IDs, a target_product, and an integer k.

A product should be counted only from sessions that contain target_product at least once. In every such session, count every occurrence of every other product in that session, and ignore the target product itself. Then return the k product IDs with the highest total co-view counts as recommendations.

If there are fewer than k distinct products, return all of them. If two products have the same frequency, return the smaller product ID first.

Design an efficient algorithm for this recommendation task and discuss how you would structure the code for production-quality Java.