Tap here to switch tabs
Problem
Submissions

Problem: Transform Array to All Equal Elements

med
30 min
Try to solve the Transform Array to All Equal Elements problem.

Statement

You are given an integer array nums of length n, where each element is either 11 or −1-1, and an integer k.

In one operation, you can select an index i such that 0≤i<n−10 \le i < n - 1 and multiply both nums[i] and nums[i + 1] by −1-1.

Return true if it is possible to make all elements in nums equal using at most k operations, and false otherwise.

Constraints:

  • 1≤n==1 \le n == nums.length ≤105\le 10^5

  • nums[i] is either −1-1 or 11.

  • 1≤k≤n1 \le k \le n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Transform Array to All Equal Elements

med
30 min
Try to solve the Transform Array to All Equal Elements problem.

Statement

You are given an integer array nums of length n, where each element is either 11 or −1-1, and an integer k.

In one operation, you can select an index i such that 0≤i<n−10 \le i < n - 1 and multiply both nums[i] and nums[i + 1] by −1-1.

Return true if it is possible to make all elements in nums equal using at most k operations, and false otherwise.

Constraints:

  • 1≤n==1 \le n == nums.length ≤105\le 10^5

  • nums[i] is either −1-1 or 11.

  • 1≤k≤n1 \le k \le n