Minimum Cost to Move Chips to The Same Position Problem

Minimum Cost to Move Chips to The Same Position Problem — ExecCode Easy DSA Practice

Solve the Minimum Cost to Move Chips to The Same Position problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description We have n chips, where the position of the i^th chip is position[i]. Your task is to compute the required answer and return the minimum cost needed to move all the chips to the same position. We need to move all the chips to the same position. In one step, we can change the position of the i^th chip from position[i] to: - position[i] + 2 or position[i] - 2 with cost = 0. - position[i] + 1 or position[i] - 1 with cost = 1.

Examples

Input {"position": [1, 2, 3]}; Output 1. Input {"position": [2, 2, 2, 3, 3]}; Output 2

Constraints

1 <= position.length <= 100 1 <= position[i] <= 10^9

Practice Minimum Cost to Move Chips to The Same Position free on ExecCode. Browse DSA problems, topic map, and placement guides.