cswork / OAOpen practice workspace

VisaOA #10

Get Max Sum after K Operations

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)GreedyStacks & Heaps

Given an integer n and an integer array arr[n]. Choose at most k operations. Each operation picks an index i and does arr[i] = arr[i] · arr[i+1]. Maximize the sum of all elements after performing operations.

Example: arr = [2, 3, 4], k = 1 → either keep sum 9, or replace arr[0] with 2*3 = 6 (sum 13), or replace arr[1] with 3*4 = 12 (sum 18). Answer 18.

Editorial

Loading solution…