Practice Transform Array to All Equal Elements
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given nums containing only 1 and -1, one operation selects an adjacent pair and changes the sign of both values. You may select the same pair more than once. Return whether at most k operations can make every entry equal.
Source: Transform Array to All Equal Elements on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,-1,1,-1,1], k = 3
Output
true
# Example 2
Input
nums = [-1,-1,-1,1,1,1], k = 5
Output
false
Constraints
1 <= n == nums.length <= 10^5
nums[i] is either -1 or 1.
1 <= k <= n
Related LeetCode Problems
Practice more problems similar to Transform Array to All Equal Elements.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.