Solve three OA coding questions
Booking.comSoftware Engineer · Online AssessmentLast updated
This 90-minute assessment evaluates algorithmic problem-solving skills including string manipulation and grouping for anagram detection, digit-level reasoning for one-swap maximization, and text tokenization with aggregation and ranking for sentiment-based scoring.
You are given a 90-minute online assessment containing three coding questions. Implement solutions for all questions.
Question 1: Group strings that are 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: array of lowercase strings (may include duplicates)
Output
- A list of groups (each group is a list of strings). Order of groups and order within a group do not matter.
Constraints (typical)
1 <= len(strs) <= 10^40 <= len(strs[i]) <= 100
Question 2: Maximize an integer by swapping two digits at most once
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: non-negative integer
Output
- Maximum integer achievable after at most one swap
Constraints (typical)
0 <= num <= 10^8
Question 3: Rank hotels by review sentiment and return top-k
You are given:
- A set of positive keywords and negative keywords.
- A list of hotel reviews, each associated with a
hotel_id. - An integer
k.
Compute each hotel’s total sentiment score by scanning all its reviews.
Scoring rules
- Tokenize each review into words by splitting on non-letter characters (punctuation and symbols are separators).
- Comparison is case-insensitive.
- For every word occurrence:
- If the word is in the positive set: +1
- If the word is in the negative set: -1
- Otherwise: 0
- A hotel’s total score is the sum across all its reviews.
Task
Return the top k hotel IDs ranked by:
- Higher total score first
- If tied, smaller
hotel_idfirst
Input (one reasonable spec)
positive_keywords: string or list of wordsnegative_keywords: string or list of wordshotel_ids: array of integers, parallel toreviewsreviews: array of stringsk: integer
Output
- Array of
khotel IDs in sorted ranking order
Constraints (typical)
1 <= len(reviews) == len(hotel_ids) <= 10^5- Total review text length up to ~
10^6 1 <= k <= number_of_distinct_hotels
Notes
- If a hotel has multiple reviews, aggregate them.
- If there are fewer than
khotels (in some variants), return all hotels sorted by the same rule.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.