Amazon Interview Question
SDE-2sInterview Type: In-Person
class Movie {
string m_movieId;
float m_rating;
vector<Movie *> m_similarMovies;
public:
bool visited = false;
Movie(string movieId, float rating): m_movieId(movieId), m_rating(rating) {}
string getId() const { return m_movieId; }
float getRating() const { return m_rating; }
void addSimilarMovies(Movie *movie) {
m_similarMovies.push_back(movie);
movie->m_similarMovies.push_back(this);
}
vector<Movie*>& getSimilarMovies() {
return m_similarMovies;
}
};
Yes and sorry if I wasn't clear but this was specifically about that section at the bottom of product description page where we show people who bought this product also bought these... and question was how would you design storage and data structure to enable fast retrieval of products so that page rendering isn't slowed down.
My solution was to have a graph in cache where each product has edges to its related 20 products and a hashmap with product id and product node in there so we can quickly retrieve current product using product id and then its related 20 products using edges. Then he asked me to implement a class for this and then asked me how would you test this.
He then dug deeper into how many products would you store and how much memory would you need? etc.
Amazon recommendation system is not code, but mathematics and statistics, specifically linear algebra.
- NoOne February 09, 2017Here are links to how they have implemented it.
[ cs.umd.edu/~samir/498/Amazon-Recommendations.pdf ]
[ google.co.in/patents/US8095521 ]