As reported: Booking Holdings SDE-II (Bangalore), 2025, round 1 (coding, one hour on HackerRank, interviewer from the Fintech platform): an abstract problem statement about a credit card limit and authorize and capture transactions, with given business rules. Write code that supports the validations and decides whether a given transaction can be processed. Fully working code was not expected in every round; one rule — clearing the held amount once the holding period expires — would need a scheduled job, and in one round the candidate and interviewer agreed to skip it. The same question was asked again in a later loop and cleared.
A credit card has a credit limit creditLimit. Two kinds of transactions arrive in time order:
- AUTHORIZE
id,amount— reserve (hold)amounton the card under the new authorizationid. - CAPTURE
id,amount— chargeamountagainst the earlier authorizationid.
The card's available credit is creditLimit − (sum of captured amounts) − (sum of active holds). A hold expires holdPeriod time units after its authorization: a hold created at time t is active while the current time is < t + holdPeriod. Before processing a transaction at time now, every hold with t + holdPeriod <= now expires and its amount is released.
Process the transactions in order and return, for each one, "APPROVED" or the first rule it breaks:
AUTHORIZE, checked in this order:
amount <= 0→"INVALID_AMOUNT"idwas already used by an approved authorization (active, captured or expired) →"DUPLICATE_ID"amount> available credit →"INSUFFICIENT_LIMIT"- otherwise
"APPROVED": a hold ofamountis created.
CAPTURE, checked in this order:
amount <= 0→"INVALID_AMOUNT"- no approved authorization with this
id→"UNKNOWN_AUTHORIZATION" - the authorization was already captured →
"ALREADY_CAPTURED" - the hold has expired →
"AUTHORIZATION_EXPIRED" amount> the authorized amount →"EXCEEDS_AUTHORIZED_AMOUNT"- otherwise
"APPROVED": the whole hold is released andamountis charged (a capture may be smaller than the hold; the rest is freed).
Declined transactions change nothing.
Example 1
creditLimit = 1000, holdPeriod = 10
time type id amount
1 AUTHORIZE a1 600 -> APPROVED (available 400)
2 AUTHORIZE a2 500 -> INSUFFICIENT_LIMIT
3 CAPTURE a1 550 -> APPROVED (captured 550, hold released, available 450)
4 AUTHORIZE a3 450 -> APPROVED (available 0)
5 CAPTURE a1 100 -> ALREADY_CAPTURED
Example 2
creditLimit = 500, holdPeriod = 5
0 AUTHORIZE h1 400 -> APPROVED
3 AUTHORIZE h2 200 -> INSUFFICIENT_LIMIT
5 AUTHORIZE h3 200 -> APPROVED (h1 expired at time 5)
6 CAPTURE h1 400 -> AUTHORIZATION_EXPIRED
7 CAPTURE h3 250 -> EXCEEDS_AUTHORIZED_AMOUNT
8 CAPTURE zz 10 -> UNKNOWN_AUTHORIZATION
Example 3
creditLimit = 100, holdPeriod = 10
0 AUTHORIZE x 0 -> INVALID_AMOUNT
1 AUTHORIZE x 100 -> APPROVED
2 AUTHORIZE x 1 -> DUPLICATE_ID
3 CAPTURE x -5 -> INVALID_AMOUNT
4 CAPTURE x 100 -> APPROVED
5 AUTHORIZE y 1 -> INSUFFICIENT_LIMIT
Constraints: 1 <= n <= 2000 transactions, 1 <= creditLimit <= 10^9, 1 <= holdPeriod <= 10^6, 0 <= times[i] <= 10^7 and non-decreasing, -10^9 <= amounts[i] <= 10^9, ids are 1–10 character strings.
Code runner format: one JSON value per line: creditLimit, holdPeriod, times, types, ids, amounts (the last four are parallel arrays; types[i] is "AUTHORIZE" or "CAPTURE"). Implement processTransactions(creditLimit, holdPeriod, times, types, ids, amounts) returning the list of results.