FastPrepFind Accounts with Negative Converted Balances

Find Accounts with Negative Converted Balances

Stripe logoStripe● MediumINTERNPHONE SCREEN
Learn

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,denominator

An amount in that currency converts to base units as:

amount * numerator / denominator

Each financial record has the form:

account,currency,amount

amount 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.

What the interview report shared

The reported internship team screen used financial records, currency conversion, and balance checks. The exact record grammar, conversion model, and requested output were not preserved.

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 * numerator and final balance fit in a signed 64-bit integer.

More Stripe problems

See Stripe hiring insights
public String[] accountsWithNegativeBalance(String[] rates, String[] records) {
    // write your code here
}
rates["USD,1,1","EUR,11,10"]
records["acct_a,USD,100","acct_a,EUR,-100","acct_b,EUR,200","acct_b,USD,-50"]
expected["acct_a"]
Checking account…