FastPrepSubarray Removal

Subarray Removal

The D.E. Shaw Group logoThe D.E. Shaw Group● MediumOA
Learn

Problem statement

Given an array arr of n integers, find the number of its subarrays such that removing the subarray creates a non-empty array that is sorted in increasing order.

Note: A subarray is defined as any contiguous segment of the array.

Function

subarrayRemoval(arr: int[]) → int

Examples

Example 1

arr = [1, 2, 1, 2]return = 7
Example 1 illustration

Constraints

  • O_O

More The D.E. Shaw Group problems

See The D.E. Shaw Group hiring insights
public int subarrayRemoval(int[] arr) {
  // write your code here
}
arr[1, 2, 1, 2]
expected7
Checking account…