Dynamic Programming21 sections · 916 units
Open in Course

Making Array Beautiful - Problem Statement

Another variant

Make array alternating: even indices have even values, odd indices have odd values. Minimum changes. Split into two problems: even indices should be even, odd indices should be odd.

Rounding to nearest valid value. Cost: for even index with value vv, cost to make even is vmod2v \mod 2. For odd index, cost to make odd is (v+1)mod2(v + 1) \mod 2. This is a simpler structure. Slope Trick applies if we generalize to 'make non-decreasing with parity constraints'.