← Booking.com Interview Insights
Start by clarifying the problem: define how keywords map to scores (e.g., positive +1, negative -1), how to detect keywords in reviews (e.g., tokenization and lookup in a dictionary), and how to aggregate scores per hotel. Then outline an efficient algorithm: iterate through each review, compute its score, accumulate per hotel, and finally sort hotels by total score to extract top-K using a heap or sorting.
Pro tip: Mention that you would preprocess the keyword list into a hash set for O(1) lookups and consider using a min-heap of size K to avoid sorting all hotels, which is crucial for large datasets. Also, discuss handling ties and potential normalization by review count to avoid bias toward hotels with many reviews.
Ask clarifying questions about keyword detection (exact match, case sensitivity, stemming), scoring weights (e.g., +1 for positive, -1 for negative), and whether to normalize by number of reviews. Define the output format: list of top-K hotels with their scores.
Store keywords in a hash set for O(1) lookup. Use a hash map to accumulate scores per hotel. If K is much smaller than the number of hotels, use a min-heap of size K to track top hotels.
For each review, tokenize the text (e.g., split on whitespace and punctuation), check each token against the keyword set, and update the hotel's score. Handle multiple occurrences of the same keyword in a review (e.g., count each occurrence or only once).
After processing all reviews, sort hotels by score descending (or use a heap) and return the top K. If scores tie, define a tie-breaking rule (e.g., alphabetical order or higher review count).
Discuss time complexity: O(R * L + H log H) where R is number of reviews, L average review length, H number of hotels; or O(R * L + H log K) with heap. Mention edge cases: no reviews, empty keyword list, K larger than number of hotels, and negative scores.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.