C_o_d_e__'s blog

By C_o_d_e__, history, 6 days ago, In English

you have an array in one operation choose two different element and remove from array return minimum length of array
you can do this operation any number of times

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Use greedy and don't use dp because why not

»
6 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Store the count of all elements using a map.

If there is an element whose count x>floor(n/2) then answer is x-(n-x);

Else answer is 0 if n is even and 1 if n is odd.

(n=size of the array)