Redbus conducts its First round on Hackerath platform, the exam goes for around 1.30 hours and the pattern keeps changing
23 - aptitude,technical MCQ questions AND 3 Coding questions (Medium to Hard)
Water tank problem and the question is here
You have exactly N water tankers. Each of the tanker has a capacity of Ci, and contains Wi, amount of water. You can transfer any amount of water from one tanker to another, any number of times. The total amount of water is the sum of the amount of water in all the tankers. You have to transport the total amount of water to another city You need to find the minimum number of tankers required to transport the total amount of water
Example
Consider N-2 C-[2,2] W-[1 ,1] You must determine the minimum number of tankers required: We can transfer water of tank 1 to tank 2. So, we required only 1 tanker.
Function description returns the count of c
N:Represents the number of tankers. C: An array of size N, represents the Capacity in the tankers
W: An array of size N, represents the current water in the tankers
Here is my approach
n = int(input())
count = 0
total_remaining = []
c = [int(y) for y in input("Enter multiple values\n").split()] [:n]
w = [int(x) for x in input("Enter multiple values\n").split()] [:n]
print("Water tanks are:",w)
print("Capacity is:",c)
total_capacity = sum(c)
print("total_capacity:",total_capacity)
total_water = sum(w)
print("total water:",total_water)
total_remaining= [c[i]-w[i] for i in range(min(len(w), len(c)))]
print(total_remaining)
for i in range(len(total_remaining)):
if total_water>0:
count+= 1
total_water -= total_remaining[i]
print("remaing water is:",total_water)
print("The water tanker required is:",count-1)
Comment a better Version here !