SRIB(Samsung) OA
Anonymous User
738

Was contacted by the recruiter to attend the test. Had 1 question. 4 hrs to solve.

There are N number of medicines to be transported from the factory to the pharmacy using a truck.
There is a container array C with C[i] denoting the number of medicines the ith container can be filled with.
There is only 1 truck available and it can carry at most 2 containers per trip. During transportation a container has to be completely filled. 

Calculate the minimum number of trips required to transport all the medicines to the pharmacy.
If its not possible to transport the medicines with the given container capacity, return -1.

PS: Containers can be reused only in separate trips i.e., C[i] can be used in trip 1 as well as trip[2] but not twice in trip[1]. 
    The truck can be loaded with just one container as well.

Eg: N = 6, C[i] = [1,3,2]
Ans: 2 trips. 1st trip transports 3+2 (5) medicines and second trip transports the remaining 1 medicine.

Eg: N = 8, C[i] = [6,5,7]
Ans: -1. If trip 1 is done with C[0] we have 2 medicines left but it cannot be transported with the available containers since a container has to be completely filled. 
Same is the case when we start with C[1] or C[2]
Comments (6)