#3574
Maximize Subarray GCD Score
international master · 2110 · lc hard +32 · 24.8% accepted · 46 likes · top 4%
Description
Given a positive integer array nums and an integer k, you may double the value of at most k distinct elements (each element doubled at most once).
The score of a contiguous subarray is its length multiplied by the GCD of all its elements.
Return the maximum score achievable over all contiguous subarrays of the modified array.
Note:
- The GCD of an array is the largest integer that divides every element evenly.
Code
1
2
3