FastPrepMost Transactions Kept Without Going Negative
Problems/Most Transactions Kept Without Going Negative

Most Transactions Kept Without Going Negative

DocuSign logoDocuSign● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from May 2025 lists this in its first interview round. The goal is to throw out as few transactions as possible so the account never goes into the red. Any transaction may be skipped, and the ones that stay still happen in their original order.

The report gives no limits or examples. It does not say the starting balance, or whether to return the transactions or just how many. Here the balance starts at 0, a balance of exactly 0 is fine, and you return only the count. The list has 1 to 10,000 values from -10,000 to 10,000. We wrote the examples.

Our version is about 90% the same as the reported question.

An account starts with a balance of 0. You are given a list of transactions in time order. A positive value is a deposit, a negative value is a withdrawal, and 0 changes nothing.

You may skip any transactions you like. The ones you keep are applied in their original order. After each kept transaction, the balance must be 0 or more.

Return the largest number of transactions you can keep. Keeping none is allowed, so the answer is at least 0.

Function

longestSafeTransactions(transactions: int[]) → int

Examples

Example 1

transactions = [3,-4,2,-1,-2]return = 4

Keep 3, skip -4, then keep 2, -1 and -2. The balance goes 3, 5, 4, 2 and never drops below 0. Keeping -4 after 3 would make the balance -1, so at most 4 transactions fit. The answer is 4.

Example 2

transactions = [2,-2,-1,-1]return = 3

Keeping 2 and -2 first leaves a balance of 0, and then neither -1 fits, which gives only 2. Skipping -2 instead and keeping 2, -1, -1 gives balances 2, 1, 0, so 3 transactions fit. The answer is 3.

Example 3

transactions = [-5,-1]return = 0

The balance starts at 0, so any withdrawal kept first would make it negative. No transaction can be kept, and the answer is 0.

Constraints

  • 1 <= transactions.length <= 10^4
  • -10^4 <= transactions[i] <= 10^4

More DocuSign Onsite Interview questions

  • Count Binary SubstringsONSITE INTERVIEW · Seen Sep 2026
  • Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
  • JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
  • Three-Part Splits With a Light MiddleONSITE INTERVIEW · Seen May 2025
  • Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
  • Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Order of a Linked ListONSITE INTERVIEW · Seen Feb 2020

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
  • Maximum Stock Profit with Unlimited TransactionsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Jump Game IIOracle · ONSITE INTERVIEWOracle interview questions
  • Maximum Stock Profit with Transaction LimitsMeta · ONSITE INTERVIEWMeta interview questions
  • Jump Game IITripjack · ONSITE INTERVIEWTripjack interview questions
  • Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
  • Return a Minimum-Coin Change BreakdownDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Best Time to Buy and Sell Stock IIHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions

Interview reports that mention this question

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)
  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int longestSafeTransactions(int[] transactions) {
        // Write your code here.
    }
}
Checking account…