aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-10-01 22:16:25 -0600
committerJack Sangdahl <[email protected]>2025-10-01 22:16:25 -0600
commitfe3b2be09b8b0cb82d2a40ee481fa74735dbf938 (patch)
tree88ac951d8c77ba361291a5ffb3afb5bf1fb7683e
parent01585d45e77abeb96336aac00896b11ad0298956 (diff)
downloadleetcode-fe3b2be09b8b0cb82d2a40ee481fa74735dbf938.tar.gz
leetcode-fe3b2be09b8b0cb82d2a40ee481fa74735dbf938.zip
3100. water bottles 2
-rw-r--r--water_bottles2.c27
-rw-r--r--water_bottles2.py49
2 files changed, 76 insertions, 0 deletions
diff --git a/water_bottles2.c b/water_bottles2.c
new file mode 100644
index 0000000..fe624b1
--- /dev/null
+++ b/water_bottles2.c
@@ -0,0 +1,27 @@
+// 3100. Water Bottles II
+#include "leetcode.h"
+
+/*
+ * you are given two integers 'numBottles' and 'numExchange'. 'numBottles'
+ * represents the number of full water bottoles that you are initially given. in
+ * one operation, you can perform one of the following operations: drink any
+ * number of full bottles, turning them into empty bottles, or exchange
+ * 'numExchange' empty bottles with one full water bottle, then increase
+ * 'numExchange' by 1. return the maximum number of water bottles you can drink
+ */
+
+int maxBottlesDrunk(int numBottles, int numExchange) {
+ int ans = numBottles;
+ while (numBottles >= numExchange) {
+ numBottles -= numExchange;
+ ans++;
+ numExchange++;
+ numBottles++;
+ }
+ return ans;
+}
+
+int main() {
+ printf("%d\n", maxBottlesDrunk(13, 6)); // expect: 15
+ printf("%d\n", maxBottlesDrunk(10, 3)); // expect: 13
+}
diff --git a/water_bottles2.py b/water_bottles2.py
new file mode 100644
index 0000000..19af620
--- /dev/null
+++ b/water_bottles2.py
@@ -0,0 +1,49 @@
+# 3100. Water Bottles II
+
+"""
+you are given two integers 'numBottles' and 'numExchange'. 'numBottles'
+represents the number of full water bottoles that you are initially given. in
+one operation, you can perform one of the following operations: drink any
+number of full bottles, turning them into empty bottles, or exchange
+'numExchange' empty bottles with one full water bottle, then increase
+'numExchange' by 1. return the maximum number of water bottles you can drink
+"""
+
+
+class Solution(object):
+ def maxBottlesDrunk(self, numBottles, numExchange):
+ """
+ :type numBottles: int
+ :type numExchange: int
+ :rtype: int
+ """
+
+
+class Solution(object):
+ def maxBottlesDrunk(self, numBottles, numExchange):
+ """
+ :type numBottles: int
+ :type numExchange: int
+ :rtype: int
+ """
+ ans = numBottles
+ while numBottles >= numExchange:
+ numBottles -= numExchange - 1
+ numExchange += 1
+ ans += 1
+ return ans
+
+
+if __name__ == "__main__":
+ ans = numBottles
+ while numBottles >= numExchange:
+ numBottles -= numExchange - 1
+ numExchange += 1
+ ans += 1
+ return ans
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.maxBottlesDrunk(13, 6))
+ print(obj.maxBottlesDrunk(10, 3))