Minimum Removals to Make Sum Even

Published by Helen Yu in

Create a function that returns the minimum number of removals to make the sum of all elements in an array even.

Examples

minimum_removals([1, 2, 3, 4, 5]) ➞ 1

minimum_removals([5, 7, 9, 11]) ➞ 0

minimum_removals([5, 7, 9, 12]) ➞ 1

Notes

  • If the sum is already even, return 0 (see example #2).
  • The output will be either 0 or 1.
Watch a quick demo on how Edabit works.