PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates skill in matching records across unsorted collections, focusing on data structures, aggregation and handling one-to-one and one-to-many relationships between bookings and payments.

  • medium
  • Booking
  • Coding & Algorithms
  • Software Engineer

Match Bookings to Payments

Company: Booking

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given two unsorted lists: - `bookings`: each record contains at least a unique `booking_id` - `payments`: each record contains at least a `booking_id` indicating which booking the payment belongs to For each booking, determine whether a payment has been made for that booking. Clarify your expected output, for example: - return a boolean for a single booking, or - return a mapping/list showing whether each booking has at least one matching payment Follow-up: - How would your approach change if one booking can have multiple payment records?

Quick Answer: This question evaluates skill in matching records across unsorted collections, focusing on data structures, aggregation and handling one-to-one and one-to-many relationships between bookings and payments.

Part 1: Determine Whether Each Booking Has a Matching Payment

You are given two unsorted lists of booking IDs. `bookings` contains unique booking IDs, and `payments` contains the booking ID referenced by each payment record. For every booking in `bookings`, determine whether there is at least one payment with the same booking ID. Return the results as a list of booleans in the same order as `bookings`.

Constraints

  • `0 <= len(bookings), len(payments) <= 200000`
  • `bookings` contains unique integers
  • `0 <= booking_id <= 10^9`
  • `payments` may contain duplicate booking IDs
  • `payments` may contain booking IDs that do not exist in `bookings`

Examples

Input: ([101, 55, 78], [78, 101])

Expected Output: [True, False, True]

Explanation: Bookings 101 and 78 appear in `payments`, but 55 does not.

Input: ([1, 2, 3], [3, 3, 4, 1])

Expected Output: [True, False, True]

Explanation: Duplicate payments for booking 3 still only mean `True`. Payment 4 is ignored because it has no matching booking.

Input: ([10, 20], [])

Expected Output: [False, False]

Explanation: There are no payments, so no booking has been paid.

Input: ([], [1, 2])

Expected Output: []

Explanation: With no bookings, the result is an empty list.

Hints

  1. Checking every payment for every booking is too slow for large inputs. Can you preprocess `payments` for fast lookup?
  2. The output order must match the original `bookings` list.

Part 2: Count Payment Records for Each Booking

You are given two unsorted lists of booking IDs. `bookings` contains unique booking IDs, and `payments` contains the booking ID referenced by each payment record. A single booking can now have multiple payment records. For every booking in `bookings`, return how many payment records belong to it. The result must be in the same order as `bookings`.

Constraints

  • `0 <= len(bookings), len(payments) <= 200000`
  • `bookings` contains unique integers
  • `0 <= booking_id <= 10^9`
  • `payments` may contain duplicate booking IDs
  • `payments` may contain booking IDs that do not exist in `bookings`

Examples

Input: ([101, 55, 78], [78, 101, 78, 78])

Expected Output: [1, 0, 3]

Explanation: Booking 101 has 1 payment, 55 has none, and 78 has 3.

Input: ([1, 2, 3], [3, 3, 4, 1, 2, 2, 2])

Expected Output: [1, 3, 2]

Explanation: Booking 1 appears once, 2 appears three times, and 3 appears twice. Payment 4 is ignored.

Input: ([10, 20], [])

Expected Output: [0, 0]

Explanation: No payments means every booking has count 0.

Input: ([], [1, 2, 2])

Expected Output: []

Explanation: With no bookings, the result is an empty list.

Input: ([7], [7, 7, 7])

Expected Output: [3]

Explanation: The single booking has three matching payment records.

Hints

  1. Instead of only tracking whether a payment exists, track how many times each payment booking ID appears.
  2. A hash map/dictionary can store the frequency of each booking ID in `payments`.
Last updated: May 23, 2026

Related Coding Questions

  • Solve three OA coding questions - Booking (medium)

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.