Solve three OA coding questions
Online Assessment: Three Coding Questions
This online assessment consists of three distinct coding questions to be completed within a 90-minute timeframe. You are required to implement solutions for all questions.
Question 1: Group Anagrams
Given an array of strings, strs, group the strings into lists where each list contains strings that are anagrams of each other.
Input
strs: An array of lowercase strings, which may include duplicates.
Output
- A list of groups, where each group is itself a list of strings. The order of groups and the order of strings within a group do not matter.
Constraints
1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100
Question 2: Maximize Integer by Swapping Two Digits
Given a non-negative integer num, you may swap at most one pair of its digits (or perform no swap). Return the maximum value you can obtain.
Input
num: A non-negative integer.
Output
- The maximum integer achievable after performing at most one swap.
Constraints
0 <= num <= 10^8
Question 3: Rank Hotels by Review Sentiment and Return Top K
You are provided with a set of positive keywords, a set of negative keywords, a list of hotel reviews each associated with a hotel_id, and an integer k. Your task is to compute each hotel’s total sentiment score by scanning all its reviews and then return the top k hotel IDs.
Scoring Rules
- Each review must be tokenized into words by splitting on any non-letter characters (punctuation and symbols act as separators).
- Word comparisons are case-insensitive.
- For every word occurrence:
- If the word is in the positive keyword set, add
+1to the score. - If the word is in the negative keyword set, add
-1to the score. - Otherwise, add
0.
- If the word is in the positive keyword set, add
- A hotel’s total score is the sum of scores across all its associated reviews.
Task
Return an array of the top k hotel IDs, ranked by:
- Higher total score first.
- If total scores are tied, smaller
hotel_idfirst.
Input
positive_keywords: A string or list of words representing positive sentiment.negative_keywords: A string or list of words representing negative sentiment.hotel_ids: An array of integers, wherehotel_ids[i]corresponds to the hotel ID forreviews[i].reviews: An array of strings, wherereviews[i]is a review text.k: An integer representing the number of top hotels to return.
Output
- An array of
khotel IDs in the specified sorted ranking order.
Constraints
1 <= len(reviews) == len(hotel_ids) <= 10^5- Total length of all review texts combined is up to approximately
10^6characters. 1 <= k <= number_of_distinct_hotels
Notes
- If a hotel has multiple reviews, their scores must be aggregated.
- If there are fewer than
kdistinct hotels, return all available hotels sorted by the same rules.
AI interview prep
Core dilemma
Demonstrating breadth of algorithmic proficiency and efficient data processing under time constraints, particularly for large-scale text analysis and aggregation in Question 3, while ensuring robust and clean code across all problems.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Solve three OA coding questions
Online Assessment: Three Coding Questions
This online assessment consists of three distinct coding questions to be completed within a 90-minute timeframe. You are required to implement solutions for all questions.
Question 1: Group Anagrams
Given an array of strings, strs, group the strings into lists where each list contains strings that are anagrams of each other.
Input
strs: An array of lowercase strings, which may include duplicates.
Output
- A list of groups, where each group is itself a list of strings. The order of groups and the order of strings within a group do not matter.
Constraints
1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100
Question 2: Maximize Integer by Swapping Two Digits
Given a non-negative integer num, you may swap at most one pair of its digits (or perform no swap). Return the maximum value you can obtain.
Input
num: A non-negative integer.
Output
- The maximum integer achievable after performing at most one swap.
Constraints
0 <= num <= 10^8
Question 3: Rank Hotels by Review Sentiment and Return Top K
You are provided with a set of positive keywords, a set of negative keywords, a list of hotel reviews each associated with a hotel_id, and an integer k. Your task is to compute each hotel’s total sentiment score by scanning all its reviews and then return the top k hotel IDs.
Scoring Rules
- Each review must be tokenized into words by splitting on any non-letter characters (punctuation and symbols act as separators).
- Word comparisons are case-insensitive.
- For every word occurrence:
- If the word is in the positive keyword set, add
+1to the score. - If the word is in the negative keyword set, add
-1to the score. - Otherwise, add
0.
- If the word is in the positive keyword set, add
- A hotel’s total score is the sum of scores across all its associated reviews.
Task
Return an array of the top k hotel IDs, ranked by:
- Higher total score first.
- If total scores are tied, smaller
hotel_idfirst.
Input
positive_keywords: A string or list of words representing positive sentiment.negative_keywords: A string or list of words representing negative sentiment.hotel_ids: An array of integers, wherehotel_ids[i]corresponds to the hotel ID forreviews[i].reviews: An array of strings, wherereviews[i]is a review text.k: An integer representing the number of top hotels to return.
Output
- An array of
khotel IDs in the specified sorted ranking order.
Constraints
1 <= len(reviews) == len(hotel_ids) <= 10^5- Total length of all review texts combined is up to approximately
10^6characters. 1 <= k <= number_of_distinct_hotels
Notes
- If a hotel has multiple reviews, their scores must be aggregated.
- If there are fewer than
kdistinct hotels, return all available hotels sorted by the same rules.