The following question has been asked in coding test of Atlassian, Cloudera, IBM
People say to use binary Search I can’t see how. Could community please explain it to me and provide with code if possible. This question does not have solution over Internet
You have four input parameters:
Cartridges, Dollars, recycleReward, perksCost.
One has two options:
Recycle one cartridge and get recycleReward amount of dollars
Combine one cartridge and perksCost amount to get a perk item.
we need to maximise the perk items one can buy.
ex: 10, 10, 2, 2
Initially there are 10 cartridges, 10 dollars with the person.
If the persone recycles 3 cartridges he has 7 cartridges and 16 dollars (10 initial + 3*2(recycleReward)).
we can combine 7 cartridges and 14 dollars to buy 7 perk items(as each item costs 1 cartridge and 2 dollars(perksCost)).