Loading Now

arrayErasing

You are given an array A of zeros and ones. With each operation you are allowed to remove consecutive equal elements (you can remove just one element if there are no equal neighboring elements).

How many operations will it take to remove all of the elements from the given array?

Example

  • a = [1, 1, 1, 1] , output arrayErasing(a) = 1
  • a = [0, 1, 1, 1, 0], output arrayErasing(a) = 2

Input/Output

  • [execution time limit] 4 seconds (py)

  • [input] array.integer A

    array of 0s and 1s

  • [output] integer

    • minimum number of operations

Post Comment

Contact