File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 2169
2169
3095|[ Shortest Subarray With OR at Least K I] ( ./solutions/3095-shortest-subarray-with-or-at-least-k-i.js ) |Easy|
2170
2170
3097|[ Shortest Subarray With OR at Least K II] ( ./solutions/3097-shortest-subarray-with-or-at-least-k-ii.js ) |Medium|
2171
2171
3099|[ Harshad Number] ( ./solutions/3099-harshad-number.js ) |Easy|
2172
+ 3100|[ Water Bottles II] ( ./solutions/3100-water-bottles-ii.js ) |Medium|
2172
2173
3105|[ Longest Strictly Increasing or Strictly Decreasing Subarray] ( ./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js ) |Easy|
2173
2174
3108|[ Minimum Cost Walk in Weighted Graph] ( ./solutions/3108-minimum-cost-walk-in-weighted-graph.js ) |Hard|
2174
2175
3110|[ Score of a String] ( ./solutions/3110-score-of-a-string.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 3100. Water Bottles II
3
+ * https://leetcode.com/problems/water-bottles-ii/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given two integers numBottles and numExchange.
7
+ *
8
+ * numBottles represents the number of full water bottles that you initially have. In one
9
+ * operation, you can perform one of the following operations:
10
+ * - Drink any number of full water bottles turning them into empty bottles.
11
+ * - Exchange numExchange empty bottles with one full water bottle. Then, increase
12
+ * numExchange by one.
13
+ *
14
+ * Note that you cannot exchange multiple batches of empty bottles for the same value of
15
+ * numExchange. For example, if numBottles == 3 and numExchange == 1, you cannot exchange
16
+ * 3 empty water bottles for 3 full bottles.
17
+ *
18
+ * Return the maximum number of water bottles you can drink.
19
+ */
20
+
21
+ /**
22
+ * @param {number } numBottles
23
+ * @param {number } numExchange
24
+ * @return {number }
25
+ */
26
+ var maxBottlesDrunk = function ( numBottles , numExchange ) {
27
+ let result = 0 ;
28
+ let full = numBottles ;
29
+ let empty = 0 ;
30
+
31
+ while ( full > 0 ) {
32
+ result += full ;
33
+ empty += full ;
34
+ full = 0 ;
35
+ if ( empty >= numExchange ) {
36
+ full = 1 ;
37
+ empty -= numExchange ;
38
+ numExchange ++ ;
39
+ }
40
+ }
41
+
42
+ return result ;
43
+ } ;
You can’t perform that action at this time.
0 commit comments