Find Accounts with Negative Converted Balances
Updated
Problem statement
Apply financial records in several currencies and return the accounts whose final balance is negative after conversion to one base unit.
Each conversion rate has the form:
currency,numerator,denominatorAn amount in that currency converts to base units as:
amount * numerator / denominatorEach financial record has the form:
account,currency,amountamount is a signed integer. Every converted record is guaranteed to be exactly divisible by its denominator. Sum converted records independently for each account.
Return the account IDs whose final converted balance is less than zero, sorted in ascending lexicographic order.
Function
accountsWithNegativeBalance(rates: String[], records: String[]) → String[]Examples
Example 1
rates = ["USD,1,1","EUR,11,10"]records = ["acct_a,USD,100","acct_a,EUR,-100","acct_b,EUR,200","acct_b,USD,-50"]return = ["acct_a"]acct_a ends at 100 - 110 = -10. acct_b ends at 220 - 50 = 170.
Example 2
rates = ["A,2,1","B,1,2"]records = ["z,B,-8","a,A,-3","z,A,2","a,B,12"]return = []Both accounts finish at zero, which is not negative.
Constraints
1 <= rates.length <= 100.1 <= records.length <= 10^5.- Account IDs and currency codes are nonempty ASCII strings without commas.
- Each currency appears exactly once in
rates, and every record uses a listed currency. 1 <= numerator, denominator <= 10^6.-10^9 <= amount <= 10^9.- Every product
amount * numeratorand final balance fit in a signed 64-bit integer.
More Stripe Phone Screen questions
- Split Tender Part 4 - RefundsOA · PHONE SCREEN · Seen Nov 2026
- Merchant Payout Reserve CalculatorPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEW
- Group AnagramsWorkday · PHONE SCREEN
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREEN
- Time-Aware Search AutocompleteRoblox · PHONE SCREEN
- Top Ten Most Frequent Words in a BookRobinhood · PHONE SCREEN
- Group AnagramsEPAM · PHONE SCREEN
- Aggregate Matching IPv4 Addresses Across ResponsesPinterest · PHONE SCREEN
- Diff Two Filesystem Hash TreesCursor · PHONE SCREEN
- Find Duplicate File GroupsAnthropic · PHONE SCREEN