Count the Number of Incremovable Subarrays II
Updated
Problem statement
You are given a 0-indexed array of positive integers nums.
A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7], which is strictly increasing.
Return the total number of incremovable subarrays of nums.
Note that an empty array is considered strictly increasing.
A subarray is a contiguous non-empty sequence of elements within an array.
Function
countIncremovableSubarrays(nums: int[]) → intExamples
Example 1
nums = [1,2,3,4]return = 10
The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray.
Example 2
nums = [6,5,7,8]return = 7
The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7], and [6,5,7,8].
It can be shown that there are only 7 incremovable subarrays in nums.
Example 3
nums = [8,7,6,6]return = 3
The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing.
Constraints
1 <= nums.length <= 10^51 <= nums[i] <= 10^9
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
- Minimum Storage CapacityAmazon · OA
- Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
- K Smallest Squares from a Sorted ArrayUber · ONSITE INTERVIEWUber interview questions
- Find K Closest Elements in a Sorted ArrayLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Count Triples That Can Form a TriangleAdobe · PHONE SCREENAdobe interview questions
- Find the Duplicate in a Read-Only ArrayNutanix · PHONE SCREENNutanix interview questions