Wallet Balance on a Selected Day
Updated
Problem statement
A wallet starts with balance 0. Its daily transactions are stored in an integer array transactions: a positive value is a credit, a negative value is a debit, and zero makes no change.
Given a zero-based index selectedDay, return the wallet balance at the end of that day. Include every transaction from day 0 through selectedDay. Return a 64-bit integer.
Function
balanceOnDay(transactions: int[], selectedDay: int) → longExamples
Example 1
transactions = [100,-30,20,-10]selectedDay = 2return = 90After days 0 through 2, the balance is 100 - 30 + 20 = 90.
Example 2
transactions = [-50,80,-20]selectedDay = 0return = -50Only the first day's debit is included.
Example 3
transactions = [5,0,-2,7]selectedDay = 3return = 10The full history sums to 5 + 0 - 2 + 7 = 10.
Constraints
1 <= transactions.length <= 5000-10^6 <= transactions[i] <= 10^60 <= selectedDay < transactions.length
More BharatPe Phone Screen questions
Similar questions at other companies
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
- Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Data UpdatesExpedia · OAExpedia interview questions
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Weighted Lottery WinnersAmazon · ONSITE INTERVIEW
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions