FastPrepMaximize Strength with Disjoint Adjacent Swaps
Problems/Maximize Strength with Disjoint Adjacent Swaps

Maximize Strength with Disjoint Adjacent Swaps

Adyen logoAdyen● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report, from an Adyen HackerRank assessment, defines swaps of neighbouring elements where each element is used in at most one swap. The goal is to maximize the sum of each value times its position, counting positions from one.

We chose the number limits and the function signature.

Our version is about 98% the same as the reported question.

You are given an integer array arr. You may swap two elements that sit next to each other, as many times as you like. But each element of the original array can take part in at most one swap. So no two of your swaps may touch the same element.

After the swaps, the strength is sum(arr[i] * (i + 1)). Here i is the index counted from zero, so each value is multiplied by its position counted from one.

Return the largest strength you can get.

Function

maxWeightedStrengthAfterSwaps(arr: int[]) → long

Examples

Example 1

arr = [3,1,2]return = 13

Swapping the first two elements gives [1, 3, 2] and strength 1 + 6 + 6 = 13.

Example 2

arr = [5,1,4,2]return = 33

Swap the first two elements, and also swap the last two. No element is used in more than one swap. This gives [1, 5, 2, 4] and strength 1 + 10 + 6 + 16 = 33.

Constraints

  • 1 <= arr.length <= 8,000.
  • -10^9 <= arr[i] <= 10^9.

More Adyen interview questions

  • Count Perfect PairsOA · Seen Aug 2026
  • Best TV Show in a GenreOA · Seen May 2026
  • Search and Format ContactsPHONE SCREEN · Seen Nov 2026
  • Find the Tree DiameterONSITE INTERVIEW · Seen Aug 2026
  • Planets Queries from Planet OnePHONE SCREEN · Seen May 2026

Similar questions at other companies

  • Card Game: Best First-Player ScoreShopify · OAShopify interview questions
  • Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
  • 0/1 KnapsackConfluent · OAConfluent interview questions
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
  • Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
  • Maximum Subarray SumStraive · OA
  • Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
  • Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
  • Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
  • API Bandwidth AllocationArista Networks · OAArista Networks interview questions

Adyen interview experiences

  • Adyen Kotlin Backend Engineer Live Coding: 1 Experience
All Adyen interview questionsSee Adyen hiring insights
Saved
class Solution {
    public long maxWeightedStrengthAfterSwaps(int[] arr) {
        // Return the maximum weighted strength.
    }
}
Checking account…