iq.lab
Python starts when a code cell comes near or you run one
easyLoops and basics target 15 min

Richest customer

accounts is a table of bank balances stored as a list of lists (a list whose items are themselves lists). Row i belongs to customer i and holds one balance per bank, so accounts[i][j] is what customer i has at bank j. A balance can be negative: that account is overdrawn.

Add up a customer's row and you get their wealth. Return the largest wealth in the table, as an integer. When several customers tie for the top, the answer is still that one number.

Example 1
Inputaccounts = [[4, 1, 2], [3, 3, 3], [5, 0, 1]]Output9

The rows add up to 7, 9 and 6. The middle customer is the richest.

Example 2
Inputaccounts = [[2, 8], [7, 3], [1, 4]]Output10

The first two customers both have 10. The question asks for the amount, so the tie changes nothing.

Example 3
Inputaccounts = [[-3, 1], [2, -6]]Output-2

Both customers are overdrawn: -3 + 1 = -2 and 2 + (-6) = -4. The largest wealth is -2, not 0.

Constraints
  • 1 ≤ len(accounts) ≤ 2,000 (customers)

  • 1 ≤ len(accounts[i]) ≤ 100 (banks), and every row has the same length

  • -1,000 ≤ accounts[i][j] ≤ 1,000

Plan it first

Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.