# cook your dish here
for i in range(0,x):
Problem Link: FIFTYPE Problem - CodeChef
The logic I used here was like this;
We need the level to be 50. Charging increases the level by +2, while using reduces the level by -3.
I took a while loop with the termination condition being battery level reaching 50%. There can be three different cases here;
Case 1: Battery at 50% already. No charge or usage required, zero as output.
Case 2: Battery lower than 50%, we keep charging until it’s equals to or more than 50%.
Case 3: Battery more than 50%, we keep using the device until it’s less than or equals to 50%
You can take a look at the following code for a better understanding.