FastPrepArray Break
Problems/Array Break

Array Break

The D.E. Shaw Group logoThe D.E. Shaw Group● HardOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

There is an integer array arr of length n. Two arrays b and c are called a perfect break of arr if:

  • The lengths of arrays b and c are n.
  • Elements in array b are in non-decreasing order.
  • Elements in array c are in non-increasing order.
  • They satisfy b[i] ≥ 0, c[i] ≥ 0, and b[i] + c[i] = arr[i], for each i where 0 ≤ i < n.

Find the number of possible perfect breaks of arr. Since the number can be large, return the value modulo 1000000007, i.e., (10^9+7).

Function

perfectBreak(arr: int[]) → int

Complete the function perfectBreak in the editor.

perfectBreak has the following parameter:

int arr[n]: the num of possible perfect breaks modulo (109 + 7).

Examples

Example 1

arr = [2, 3, 2]return = 4

There are 4 possible perfect breaks of array arr:

  • b = [0, 1, 1], c = [2, 2, 1] is a perfect break because it
  • b and c have 3 elements
  • b is non-decreasing order
  • c is in non-increasing order
  • elements of b and c are 0 or more than the sums of a[i] + b[i] = [2, 3, 2], which matches arr.
  • b = [0, 1, 2], c = [2, 2, 0] is a perfect break.
  • b = [0, 2, 2], c = [2, 1, 0] is a perfect break.
  • b = [1, 2, 2], c = [1, 1, 0] is a perfect break.
  • b = [1, 3, 2], c = [1, 0, 0] is not a perfect break because b is not non-decreasing.
  • b = [1, 2, 2], c = [2, 1, 0] is not a perfect break because b[0] + c[0] ≠ arr[0].

Example 2

arr = [3, 2]return = 6

The perfect breaks are: b = [0, 0], c = [3, 2] b = [0, 1], c = [3, 1] b = [0, 2], c = [3, 0] b = [1, 1], c = [2, 1] b = [1, 2], c = [2, 0] b = [2, 2], c = [1, 0]

Constraints

  • 1 <= n <= 3000
  • 1 <= arr[i] <= 3000

More The D.E. Shaw Group interview questions

  • IPOPHONE SCREEN · Seen Nov 2026
  • Print Numbers in Turn with Three ThreadsPHONE SCREEN · Seen Nov 2026
  • Subarray Product Less Than KPHONE SCREEN · Seen Nov 2026
  • Koko Eating BananasPHONE SCREEN · Seen Nov 2026
  • Sum of Smallest Non-DivisorsPHONE SCREEN · Seen Nov 2026
  • Count Lucky TicketsOA · Seen Nov 2026
  • Count Palindrome Addition ChoicesOA · Seen Nov 2026
  • Coordinate Odd and Even Workers in OrderONSITE INTERVIEW · Seen Oct 2026
  • Minimum Taps to Water a GardenONSITE INTERVIEW · Seen Oct 2026
  • Remove the Fewest Magic BeansPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Magic Number Range CounterGraviton · OA
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Stable Workload Redistribution TreesTower Research Capital · OA
  • Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
  • Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
  • Count Divisible PermutationsDeloitte · OADeloitte interview questions
  • Count SubsequencesBank of New York Mellon · OA
  • Rob Houses Without Getting CaughtEPAM · OAEPAM interview questions
All The D.E. Shaw Group interview questionsSee The D.E. Shaw Group hiring insights
Saved
class Solution {
    public int perfectBreak(int[] arr) {
      // write your code here
    }

}
Checking account…