PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/TikTok

Match payments to invoices with fallback rules

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design robust record-matching logic that handles identifier-based matches, fallback heuristics, and numeric tolerance windows, testing competencies in data manipulation, edge-case handling, and algorithmic correctness.

  • medium
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Match payments to invoices with fallback rules

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given two datasets: - `invoices`: each invoice has `invoice_id`, `date`, `amount` - `payments`: each payment has `payment_id`, optional `invoice_id` (may be missing/empty), `date`, `amount` You must match each payment to **at most one** invoice (and each invoice to **at most one** payment) according to rules below, then output the matched invoice (or unmatched) for each payment. ## Part 1 — Match by invoice_id If a payment has a non-empty `invoice_id`, match it to the invoice with the same `invoice_id` if it exists and is not already matched. If no such invoice exists (or already matched), treat the payment as unmatched. ## Part 2 — Fallback to amount/date when no invoice_id If a payment has no `invoice_id`, attempt to match it by: - Find invoices with the **same amount** that are not already matched. - Choose the invoice with the **earliest date** among candidates. - If no candidate exists, payment remains unmatched. This logic must coexist with Part 1 (i.e., still prefer `invoice_id` when present). ## Part 3 — Forgiveness (tolerance) window You are given a non-negative integer `forgiveness`. If a payment has no `invoice_id`, it may match any unmatched invoice whose amount is within: - `invoice.amount ∈ [payment.amount - forgiveness, payment.amount + forgiveness]` Choose the invoice with the **earliest date** among candidates. ## Output For each payment (in input order), output the matched invoice id (or `None`/empty if unmatched). Also specify how you handle ties (same date) deterministically. ## Notes - Assume `date` is comparable (e.g., ISO `YYYY-MM-DD`). - Discuss complexity and data structures needed to support efficient earliest-date selection.

Quick Answer: This question evaluates a candidate's ability to design robust record-matching logic that handles identifier-based matches, fallback heuristics, and numeric tolerance windows, testing competencies in data manipulation, edge-case handling, and algorithmic correctness.

Related Interview Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Maximize sum with no adjacent elements - TikTok (medium)
TikTok logo
TikTok
Jan 6, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

You are given two datasets:

  • invoices : each invoice has invoice_id , date , amount
  • payments : each payment has payment_id , optional invoice_id (may be missing/empty), date , amount

You must match each payment to at most one invoice (and each invoice to at most one payment) according to rules below, then output the matched invoice (or unmatched) for each payment.

Part 1 — Match by invoice_id

If a payment has a non-empty invoice_id, match it to the invoice with the same invoice_id if it exists and is not already matched. If no such invoice exists (or already matched), treat the payment as unmatched.

Part 2 — Fallback to amount/date when no invoice_id

If a payment has no invoice_id, attempt to match it by:

  • Find invoices with the same amount that are not already matched.
  • Choose the invoice with the earliest date among candidates.
  • If no candidate exists, payment remains unmatched.

This logic must coexist with Part 1 (i.e., still prefer invoice_id when present).

Part 3 — Forgiveness (tolerance) window

You are given a non-negative integer forgiveness.

If a payment has no invoice_id, it may match any unmatched invoice whose amount is within:

  • invoice.amount ∈ [payment.amount - forgiveness, payment.amount + forgiveness]

Choose the invoice with the earliest date among candidates.

Output

For each payment (in input order), output the matched invoice id (or None/empty if unmatched). Also specify how you handle ties (same date) deterministically.

Notes

  • Assume date is comparable (e.g., ISO YYYY-MM-DD ).
  • Discuss complexity and data structures needed to support efficient earliest-date selection.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More TikTok•More Software Engineer•TikTok Software Engineer•TikTok Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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.