Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Arrays Similar

Try to solve the Minimum Number of Operations to Make Arrays Similar problem.

Statement

You are given two positive integer arrays nums and target of the same length n.

In one operation, you can choose two distinct indices i and j and perform the following actions:

  • Increment nums[i] by 22

  • Decrement nums[j] by 22

Two arrays are considered similar if both arrays contain the exact same elements with the same frequencies.

Return the minimum number of operations required to make nums similar to target.

Constraints:

  • n ==== nums.length ==== target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i], target[i] ≤106\leq 10^6

  • It is possible to make nums similar to target.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Operations to Make Arrays Similar

Try to solve the Minimum Number of Operations to Make Arrays Similar problem.

Statement

You are given two positive integer arrays nums and target of the same length n.

In one operation, you can choose two distinct indices i and j and perform the following actions:

  • Increment nums[i] by 22

  • Decrement nums[j] by 22

Two arrays are considered similar if both arrays contain the exact same elements with the same frequencies.

Return the minimum number of operations required to make nums similar to target.

Constraints:

  • n ==== nums.length ==== target.length

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq nums[i], target[i] ≤106\leq 10^6

  • It is possible to make nums similar to target.