man.god96's blog

By man.god96, history, 4 years ago, In English

So here's the problem -

I need to find the minimum divisions required with a divisor 'd', to equalize at least k elements in the array.

For eg. for array {64,25,33,30}, divisor=2 and k=2 ->

Divide 64 two times to get 16 and 33 one time to get 16. So array becomes {16,25,16,30} which has k=2 elements equal. And so minimum divisions required = 3.

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

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

you can use a map for each number with an array for store number of division asume your example :if we divide 25 with 2 it will be the follow :first we insert 0 in 25 array beacause there are not any dision yet then 25/2=12 and we store 1 in 12 array beacause we divide 25 once time then 12/2=6 and store 2 in 6 array because we divide 25 twice and so on .and we do this method with other number and loop over this number and get the least k division .this take o(nlogn). hope it well.