Find Maximum Number of Balanced Combinations
Updated
Problem statement
Given an array arr, the combinations are its contiguous subarrays (blocks of consecutive elements). For arr = [3, 6, 3] the combinations are:
- [3]
- [6]
- [3]
- [3, 6, 3]
- [6, 3]
- [3, 6]
A combination is considered balanced if the last element is not the largest value in that combination. If the last element is equal to the largest value, it is a largest value, so the combination is not balanced. For example, [3, 6, 3] is balanced because the last element (3) is smaller than the largest value (6).
Your task is to find the maximum number of balanced combinations, which is the number of balanced combinations of arr.
A possible custom case you can use could be arr = [99, 25, 69, 28, 32], with output 8.
Function
findMaxBalancedCombinations(arr: int[]) → int Complete the function findMaxBalancedCombinations in the editor.
findMaxBalancedCombinations has the following parameter:
int[] arr: an array of integers
Returns int: the number of balanced combinations
Examples
Example 1
arr = [3, 6, 3]return = 2All possible combinations -
- [3]
- [6]
- [3]
- [3, 6, 3]
- [6, 3]
- [3, 6]
Balanced if the last element in the combination is NOT the greatest value. Valid combinations - [3, 6, 3] --> 3 is not the greatest [6, 3] --> 3 is not the greatest
Constraints
1 <= n <= 5 * 10^4, wherenis the length ofarr1 <= arr[i] <= 10^9
More Amazon interview questions
- Get Smallest Base SegmentOA · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- 3SumPHONE SCREEN · Seen Nov 2026
- Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Get Triplet CountIBM · OAIBM interview questions
- Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 interview questions
- Product of Subset MaximaArcesium · OAArcesium interview questions
- Counting Triplets Divisible by DAT&T · OAAT&T interview questions
- Count Valid TeamsWells Fargo · OAWells Fargo interview questions
- Paint Fence Work SplitNutanix · OANutanix interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Minimum Operations to Flip Exactly K BitsGoogle · OAGoogle interview questions
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences