Maximum Index-Weighted Sum with Disjoint Swaps
Updated
Problem statement
For an integer array nums, its score is sum(i * nums[i]) using zero-based indices.
You may choose any number of pairwise-disjoint swaps, including zero. A swap may exchange any two positions, but no position may participate in more than one swap. Return the maximum attainable score.
Function
maxIndexWeightedSum(nums: int[]) → longExamples
Example 1
nums = [2,1,4,3]return = 20Swapping positions 0 and 1 and positions 2 and 3 produces [1,2,3,4] with score 20.
Example 2
nums = [-1,5,2]return = 12Swapping positions 1 and 2 gives [-1,2,5], whose score is 12.
Constraints
1 <= nums.length <= 18.-1000000 <= nums[i] <= 1000000.- The answer fits a signed 64-bit integer.
More Visa Online Assessment questions
- Count Prime Values in SubtreesOA · Seen Nov 2026
- Lock CodeOA · Seen Nov 2026
- Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
- Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
- Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
- Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
- Count Valid Space-Delimited WordsOA · Seen Oct 2026
- Earliest Common Meeting StartOA · Seen Oct 2026
- Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026
- Minimum Values with Even Powers of TwoOA · Seen Sep 2026
Similar questions at other companies
- Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Distinct OR Values of Increasing SubsequencesScale AI · OAScale AI interview questions
- Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
- Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
- Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- Minimum Racks for Server ResourcesGoogle · PHONE SCREENGoogle interview questions
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions