Maximize weighted sum with disjoint adjacent swaps
Company: Reevo
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates a candidate's competency in array manipulation, combinatorial optimization, and algorithmic reasoning about how local adjacent swaps affect a weighted global objective.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([1,3,2],)
Expected Output: 14
Explanation: Swapping 3 and 2 gives a positive gain.
Input: ([5,1,4,2],)
Expected Output: 33
Explanation: Choose non-overlapping beneficial adjacent swaps.
Input: ([1,2,3],)
Expected Output: 14
Explanation: No positive-gain swap is useful.
Input: ([7],)
Expected Output: 7
Explanation: A single element cannot be swapped.
Hints
- Each possible swap has gain arr[i] - arr[i+1].
- Run path dynamic programming over non-overlapping edges.