You are given a nums of length n, a positive integer k, and a non-negative integer maxChanges.
Alice plays a game where her objective is to collect k ones. At the beginning of the game, Alice selects an index aliceIndex such that aliceIndex nums[aliceIndex] is equal to nums[aliceIndex] becomes
Afterward, in each move, Alice can perform one of the following actions:
Select an index j such that nums[j] = 0, then set nums[j] = 1. This action can be performed at most maxChanges times in total throughout the game.
Select two adjacent indices x and y such that nums[x] = 1, and nums[y] = 0, then swap the values of nums[x] and nums[y]. If y is equal to aliceIndex, Alice immediately collects the one, and nums[y] becomes
Return the minimum number of moves required for Alice to collect k ones.
Constraints:
n
nums[i]
k
maxChanges
maxChanges numsk
You are given a nums of length n, a positive integer k, and a non-negative integer maxChanges.
Alice plays a game where her objective is to collect k ones. At the beginning of the game, Alice selects an index aliceIndex such that aliceIndex nums[aliceIndex] is equal to nums[aliceIndex] becomes
Afterward, in each move, Alice can perform one of the following actions:
Select an index j such that nums[j] = 0, then set nums[j] = 1. This action can be performed at most maxChanges times in total throughout the game.
Select two adjacent indices x and y such that nums[x] = 1, and nums[y] = 0, then swap the values of nums[x] and nums[y]. If y is equal to aliceIndex, Alice immediately collects the one, and nums[y] becomes
Return the minimum number of moves required for Alice to collect k ones.
Constraints:
n
nums[i]
k
maxChanges
maxChanges numsk