algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
3 shown · 0/261 solved

People With the Most Negative Balance

Bronze
Asked atJPMorgan Chase
Solve problem →
2000ms256MBAdded Aug 3, 2026Hash Maps

You are given three arrays of equal length describing money transfers. For each index i, person borrowers[i] borrows amounts[i] from person lenders[i].

Borrowing subtracts the amount from the borrower's running balance, and lending adds it to the lender's balance. Every person starts at a balance of 0.

After processing all records, return the name(s) of the person(s) with the smallest (most negative) final balance. If several people tie for the smallest balance, return all of them in a list sorted in ascending (lexicographic) order.

Examples

Example 1

Input: borrowers = ["a"], lenders = ["b"], amounts = [10]
Output: ["a"]
Explanation: a's balance is -10 and b's is +10, so a is the most negative.

Example 2

Input: borrowers = ["a","b"], lenders = ["c","c"], amounts = [5,7]
Output: ["b"]
Explanation: a = -5, b = -7, c = +12. b has the smallest balance.

Example 3

Input: borrowers = ["a","c"], lenders = ["b","d"], amounts = [5,5]
Output: ["a","c"]
Explanation: a = -5 and c = -5 tie for the smallest balance.

Constraints

  • 1≤1 \leq1≤ borrowers.length === lenders.length === amounts.length ≤2×104\leq 2 \times 10^4≤2×104
  • 1≤1 \leq1≤ amounts[i] ≤109\leq 10^9≤109
  • Each name is 111 to 666 lowercase English letters.
  • borrowers[i] ≠\neq= lenders[i]

Details

Solved by30 people
Time limit2000ms
Memory256MB
AddedAug 3, 20265 weeks ago
Hash Maps

More like this