FastPrepMaximum Charge After Removal
Problems/Maximum Charge After Removal

Maximum Charge After Removal

Amazon logoAmazon● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits numeric bounds. The judged core task matches the visible source at about 98%.

You are given an integer array charge. Repeat the following operation until one value remains:

  • Choose and remove one value.
  • If the removed value had a neighbor on both sides, remove those two neighbors as well and insert their sum in the same position.
  • If the removed value was the first or last value, no merge occurs.

Return the maximum possible value of the final remaining system.

Function

maximumChargeAfterRemoval(charge: int[]) → int

Examples

Example 1

charge = [-2, 4, 3, -2, 1]return = 4

First remove the leftmost value -2, leaving [4, 3, -2, 1]. Then remove the interior value -2; its neighbors 3 and 1 merge into 4, leaving [4, 4]. Remove either edge value to finish with 4.

No sequence can produce a final value greater than 4, so the answer is 4.

Constraints

  • 1 <= charge.length <= 100000
  • -10000 <= charge[i] <= 10000

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Get Minimum IncrementIBM · OAIBM interview questions
  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int maximumChargeAfterRemoval(int[] charge) {
      // write your code here
    }

}
Checking account…