Empty The Tank
Basic Accuracy: 47.03% Submissions: 720 Points: 1

Given a tank with capacity C litres which is completely filled in starting. At the end of every day, tank is filled with L litres of water and in the case of overflow extra water is thrown out. Now on i-th day i litres of water is taken out for drinking. We need to find out the day at which tank will become empty the first time.

Example 1:

Input: C = 5, L = 2
Output: 4
Explanation: At the start of 1st day,
water in tank = 5 and at the end of
the 1st day = (5 - 1) = 4 At the start
of 2nd day, water in tank = 4 + 2 = 6
but tank capacity is 5 so water = 5 and
at the end of the 2nd day = (5 - 2) = 3
At the start of 3rd day, water in
tank = 3 + 2 = 5 and at the end of the
3rd day = (5 - 3) = 2 At the start of 4th
day, water in tank = 2 + 2 = 4 and at the
end of the 4th day = (4 - 4) = 0
So final answer will be 4.


Example 2:

Input: C = 6, L = 1
Output: 4
Explanation: At the start of 1st day,
water in tank = 6 and at the end of
the 1st day = (5 - 1) = 5 At the start
of 2nd day, water in tank = 5 + 1 = 6
and at the end of the 2nd day = (5 - 2)= 3
At the start of 3rd day, water in
tank = 3 + 1 = 4 and at the end of the
3rd day = (4 - 3) = 1 At the start of 4th
day, water in tank = 1 + 1 = 2 and at the
end of the 4th day = (2 - 4) = 0
So final answer will be 4.

You dont need to read input or print anything. Complete the function minDaysToEmpty() which takes C and L as input parameter and returns the the day at which tank will become empty the first time.

Expected Time Complexity: O(logC)
Expected Auxiliary Space: O(1)

Constraints:
1<= C <=105
1<= L <=C

We are replacing the old Disqus forum with the new Discussions section given below.

to report an issue on this page.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?