FastPrepDefer Expenses to Preserve Balance
Problems/Defer Expenses to Preserve Balance

Defer Expenses to Preserve Balance

DRW logoDRW● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the fewest expenses moved to year end so that every running balance stays at or above zero. Our version is about 99% the same as the reported question.

You are given a chronological array transactions. Positive values are income and negative values are expenses. The running balance must never become negative.

You may defer an expense by removing it from its current position and appending it after every non-deferred transaction. Deferred expenses retain their relative order. Return the minimum number of expenses that must be deferred.

Function

minimumDeferredExpenses(transactions: int[]) → int

Examples

Example 1

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

Defer -5; the order [4,3,-2,1,-5] never has a negative prefix.

Example 2

transactions = [10,-4,-8,7,-6,5]return = 1

Deferring -8 is sufficient.

Example 3

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

Every original prefix already has a nonnegative balance.

Constraints

  • 1 <= transactions.length <= 100000
  • -1000000000 <= transactions[i] <= 1000000000
  • The total sum of transactions is nonnegative.

More DRW interview questions

  • Longest Equal-Frequency SubstringPHONE SCREEN · Seen Oct 2026
  • Minimize Range After Three ChangesPHONE SCREEN · Seen Oct 2026
  • Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
  • Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
  • Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
  • 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
  • Nested In-Memory Database TransactionsOA · Seen Aug 2026
  • Password Requirement CheckOA · Seen Aug 2026
  • Remove Excess Consecutive CharactersOA · Seen Aug 2026
  • Last Round for Each PlayerOA · Seen Jul 2026

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
  • Minimize Array Sum After K Halving OperationsDocuSign · PHONE SCREENDocuSign interview questions
  • Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Minimum Sum After K Ceiling HalvingsAdobe · PHONE SCREENAdobe interview questions
  • Furthest Building with Bricks and LaddersAmazon · PHONE SCREEN
  • Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions
  • Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
  • Minimum Operations to Halve an Array SumGrab · PHONE SCREENGrab interview questions
All DRW interview questionsSee DRW hiring insights
Saved
class Solution {
    public int minimumDeferredExpenses(int[] transactions) {
        // Write your code here.
    }

}
Checking account…