The Question
CodingHotel Review Sentiment Ranking
You are given a string
positive_keywords containing space-separated words, and two arrays: hotel_ids and reviews. The arrays represent reviews for various hotels where reviews[i] corresponds to hotel_ids[i]. Your task is to rank the hotels based on the number of times any of the positive_keywords appear in their reviews.
Requirements:
1. A keyword match is case-insensitive.
2. If a hotel has multiple reviews, the total count of keyword matches across all its reviews should be summed.
3. Return the list of unique hotel IDs sorted in descending order by their total match count.
4. If two hotels have the same match count, sort them by their hotel_id in ascending order.
Example:
Input:
keywords = 'smart clean breakfast'
hotel_ids = [1, 2, 1]
reviews = ['This hotel is clean', 'The breakfast is good', 'The rooms are smart and clean']
Output: [1, 2]
Explanation: Hotel 1 has 3 matches ('clean', 'smart', 'clean'). Hotel 2 has 1 match ('breakfast').Java
Hashing
Sorting
HashSet
HashMap