Problem · Array

Find Maximum Number of Balanced Combinations

Learn this problem
MediumAmazonOA
See Amazon hiring insights

Problem statement

Given an array, the valid 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. For example, [3, 6, 3] is balanced because the last element (3) is not larger than the others.

Your task is to find the maximum number of balanced combinations.

A possible custom case you can use could be - input = [99,25,69,28,32] output = 8

Function

findMaxBalancedCombinations(arr: int[]) → int

Examples

Example 1

arr = [3, 6, 3]return = 2
All 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

    ~

    More Amazon problems

    drafts saved locally
    public int findMaxBalancedCombinations(int[] arr) {
      // write your code here
    }
    
    arr[3, 6, 3]
    expected2
    checking account