Hi, so I've just attempted an online technical test. It was on hacker rank however I'm sure leetcode usually has the same and more challenged so thought i'd ask.
I could not think of a nice solution and cannot find a leetcode exercise that matches what was being asked so I'm here for someone to point me in the right direction.
The problem:
Someone has to carry water in cans and can only carry one can at a time. I was given 2 arrays, one of which had the total amount of water each can can hold and the second has the amount of water that was curently used by each can.
An example input was:
Total = [ 3 , 5 , 3 , 5 , 5]
Used = [ 3 , 2 , 1 , 3 , 1]
So can [0] has a total of 3 and is currently full. Can [1] has a total of 5 but only 2 is being used etc etc. I had to find the minimum amount of cans needed in order to be able to carry all of the water.
The solution in this example was 2 since you could take the water from can [0] and put into can [1] to fill it up. You could then take water from cans [2] and [3] and put into can [4] therefore only needing cans [2] and [4] to carry all the water.
Does anyone recognise this question and could you be able to point me in the direction of the problem on leet code or hackerrank as I cannot come up with a nice algorithm myself.
Thanks in advance