Dividing Array greedy

Check out the code if anyone is having problem