PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Reevo

Maximize weighted sum with disjoint adjacent swaps

Last updated: Mar 29, 2026

Quick Overview

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.

  • medium
  • Reevo
  • Coding & Algorithms
  • Software Engineer

Maximize weighted sum with disjoint adjacent swaps

Company: Reevo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

You are given an integer array `arr` of length `n` (0-indexed). Define the weighted sum as: `S = Σ_{i=0..n-1} arr[i] * (i + 1)`. You may perform any number of **adjacent swaps** of the form swap `arr[i]` and `arr[i+1]`, with the constraint that **each array position can be involved in at most one swap** (i.e., chosen swaps must be **non-overlapping**). Return the **maximum possible** value of `S` after performing such swaps. Constraints (typical for this OA style): `1 ≤ n ≤ 2e5`, `|arr[i]|` fits in 32-bit signed integer. Output may require 64-bit integer.

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.

Related Interview Questions

  • Output lexicographically largest DFS traversal - Reevo (medium)
  • Count all palindromic substrings - Reevo (medium)
  • Check strings against dictionary efficiently - Reevo (Medium)
Reevo logo
Reevo
Feb 2, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
2
0

You are given an integer array arr of length n (0-indexed).

Define the weighted sum as:

S = Σ_{i=0..n-1} arr[i] * (i + 1).

You may perform any number of adjacent swaps of the form swap arr[i] and arr[i+1], with the constraint that each array position can be involved in at most one swap (i.e., chosen swaps must be non-overlapping).

Return the maximum possible value of S after performing such swaps.

Constraints (typical for this OA style): 1 ≤ n ≤ 2e5, |arr[i]| fits in 32-bit signed integer. Output may require 64-bit integer.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Reevo•More Software Engineer•Reevo Software Engineer•Reevo Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.