cswork / libraryOpen practice workspace

Interview questions · Booking.com

Solve three OA coding questions

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^4
  • 0 <= 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:

  1. Higher total score first
  2. If tied, smaller hotel_id first

Input (one reasonable spec)

  • positive_keywords: string or list of words
  • negative_keywords: string or list of words
  • hotel_ids: array of integers, parallel to reviews
  • reviews: array of strings
  • k: integer

Output

  • Array of k hotel 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 k hotels (in some variants), return all hotels sorted by the same rule.

Community answers

Nothing here yet.

Join in on CSWork →