package leetcode;

/**
 * https://leetcode.com/problems/water-bottles/
 */
public class Problem1518 {
    public int numWaterBottles(int numBottles, int numExchange) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1518 prob = new Problem1518();
        System.out.println(prob.numWaterBottles(9, 3)); // 13
        System.out.println(prob.numWaterBottles(15, 4)); // 19
        System.out.println(prob.numWaterBottles(5, 5)); // 6
        System.out.println(prob.numWaterBottles(2, 3)); // 2
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/water-bottles/
 */
public class Problem1518 {
    public int numWaterBottles(int numBottles, int numExchange) {
        int answer = 0;
        while (numBottles > 0) {
            numBottles -= numExchange;
            if (numBottles < 0) {
                answer += numExchange + numBottles;
            } else {
                answer += numExchange;
            }
            numBottles++;
        }
        return answer;
    }
}

Solve problem 1518