← Booking.com Interview Insights
My first instinct was to nest loops and I caught myself before writing it out, which felt like a small win.
First, clarify the input and output formats, edge cases, and assumptions (e.g., can payments reference non-existent bookings? Are amounts integers or floats?). Then, outline an algorithm that aggregates payments per booking using a hash map, and finally compares the total paid against the amount due to assign statuses.
Pro tip: Mention that you would handle floating-point precision by using integer cents or a tolerance threshold, and discuss how to scale the solution for large datasets (e.g., streaming aggregation or distributed processing).
Ask about input types, possible missing bookings, negative payments, and whether overpayment is allowed. Confirm the expected output format (e.g., mapping from booking ID to status).
Propose using a hash map to accumulate total payments per booking ID. Iterate through payments once, summing amounts for each booking.
For each booking, compare the total paid to the amount due. Use conditional logic to assign PAID, UNPAID, UNDERPAID, or OVERPAID, handling floating-point precision carefully.
Discuss time and space complexity (O(n + m) time, O(n) space). Mention alternative approaches (e.g., sorting, database joins) and their trade-offs.
Walk through edge cases: no payments, exact payment, partial payment, overpayment, payments for unknown bookings. Suggest unit tests to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.