Problem · Dynamic Programming

Maximum Equal Deletion Sum

Learn this problem
HardMicrosoft logoMicrosoftOA
See Microsoft hiring insights

Problem statement

You have an array A, of size N. There are 3 ways to delete elements:

  • first 2 elements
  • last 2 elements
  • first and last element
  • The array size should be greater than 2, if less, you cannot make any move. The question is to find in how many (maximum) moves, you can get deletion of equal sum.

    Function

    maximumEqualDeletionSum(A: int[]) → int

    Examples

    Example 1

    A = [1, 9, 8, 9, 5, 1, 2]return = 3

    You delete:

    1. first 2 elements (1,9) = 10
    2. first and last (8,2) = 10
    3. first and last (9,1) = 10

    So, total 3 moves, 3 is the answer.

    Constraints

    🍋🍋🍊🍊

    More Microsoft problems

    drafts saved locally
    public int maximumEqualDeletionSum(int[] A) {
      // write your code here
    }
    
    A[1, 9, 8, 9, 5, 1, 2]
    expected3
    checking account