Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Move Chips to The Same Position

med
30 min
Try to solve the Minimum Cost to Move Chips to The Same Position problem.

Statement

You are given an integer array position representing the positions of multiple chips, where position[i] denotes the position of the chip at index i.

You need to move all the chips to the same position. In a single move, you can change the position of any chip from xx to:

  • x+2x + 2 or x−2x - 2 with a cost of 00.

  • x+1x + 1 or x−1x - 1 with a cost of 11.

Return the minimum total cost required to move all chips to the same position.

Constraints:

  • 1≤1 \leq position.length ≤100\leq 100

  • 1≤1 \leq position[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost to Move Chips to The Same Position

med
30 min
Try to solve the Minimum Cost to Move Chips to The Same Position problem.

Statement

You are given an integer array position representing the positions of multiple chips, where position[i] denotes the position of the chip at index i.

You need to move all the chips to the same position. In a single move, you can change the position of any chip from xx to:

  • x+2x + 2 or x−2x - 2 with a cost of 00.

  • x+1x + 1 or x−1x - 1 with a cost of 11.

Return the minimum total cost required to move all chips to the same position.

Constraints:

  • 1≤1 \leq position.length ≤100\leq 100

  • 1≤1 \leq position[i] ≤109\leq 10^9