Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Minimum Cost to Move Chips to The Same Position

Easy

Topics
ArrayMathGreedy

Chips are at positions given by nums. Moving a chip by 2 costs 0; moving it by 1 costs 1. Return the minimum total cost to move all chips to the same position. Even and odd positions split into two groups, so the answer is the size of the smaller group.

Example 1

Input:  position = [1,2,3]
Output: 1

Example 2

Input:  position = [2,2,2,3,3]
Output: 2

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 10^9
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access