Skip to content

Commit 7935c9c

Browse files
committed
Daily
1 parent 7ee3549 commit 7935c9c

37 files changed

+367
-153
lines changed

README.md

+16-15
Large diffs are not rendered by default.

markdowns/Daily_Questions.md

+41-40
Large diffs are not rendered by default.

markdowns/Questions_By_Code_Length.md

+15-14
Large diffs are not rendered by default.

markdowns/Questions_By_Recent.md

+15-14
Large diffs are not rendered by default.

markdowns/Topics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
- [Tree](<by_topic/Tree.md>) (66 completed)
1212
- [Binary Tree](<by_topic/Binary Tree.md>) (61 completed)
1313
- [Sorting](<by_topic/Sorting.md>) (55 completed)
14-
- [Math](<by_topic/Math.md>) (49 completed)
14+
- [Math](<by_topic/Math.md>) (50 completed)
1515
- [Breadth-First Search](<by_topic/Breadth-First Search.md>) (47 completed)
1616
- [Two Pointers](<by_topic/Two Pointers.md>) (44 completed)
1717
- [Linked List](<by_topic/Linked List.md>) (40 completed)
1818
- [Stack](<by_topic/Stack.md>) (37 completed)
1919
- [Greedy](<by_topic/Greedy.md>) (31 completed)
2020
- [Matrix](<by_topic/Matrix.md>) (30 completed)
21-
- [Simulation](<by_topic/Simulation.md>) (26 completed)
21+
- [Simulation](<by_topic/Simulation.md>) (27 completed)
2222
- [Design](<by_topic/Design.md>) (25 completed)
2323
- [Bit Manipulation](<by_topic/Bit Manipulation.md>) (24 completed)
2424
- [Dynamic Programming](<by_topic/Dynamic Programming.md>) (20 completed)

markdowns/_1518. Water Bottles.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# 1518. [Water Bottles](<https://leetcode.com/problems/water-bottles>)
2+
3+
*All prompts are owned by LeetCode. To view the prompt, click the title link above.*
4+
5+
*[Back to top](<../README.md>)*
6+
7+
------
8+
9+
> *First completed : July 06, 2024*
10+
>
11+
> *Last updated : July 06, 2024*
12+
13+
14+
------
15+
16+
> **Related Topics** : **[Math](<by_topic/Math.md>), [Simulation](<by_topic/Simulation.md>)**
17+
>
18+
> **Acceptance Rate** : **61.032 %**
19+
20+
21+
------
22+
23+
> ```
24+
> n=9, k=3
25+
> 13 = 9 + 3 + 1
26+
>
27+
> n=15, k=4
28+
> ans = 15 + (15//4 + 15 % 4) + ...
29+
> = 15 + ...
30+
> = 19
31+
>
32+
> ```
33+
>
34+
>
35+
> ```
36+
> (n bottles) + (n // k new bottles from trade)
37+
> + ((n // k + n % k) // k new bottles from 2nd round of trading)
38+
> + ((n // k + n % k) // k + (n // k + n % k) % k) // k
39+
> + ...
40+
>
41+
> n = k * m + r1
42+
> m = k * n + r2
43+
> n = k * o + r3
44+
> ...
45+
>
46+
> (k * m) + ...
47+
> ```
48+
49+
------
50+
51+
## Solutions
52+
53+
- [e1518 v1 O(n) Daily.py](<../my-submissions/e1518 v1 O(n) Daily.py>)
54+
- [e1518 v2 O(1).py](<../my-submissions/e1518 v2 O(1).py>)
55+
- [e1518.c](<../my-submissions/e1518.c>)
56+
- [e1518.cpp](<../my-submissions/e1518.cpp>)
57+
- [e1518.cs](<../my-submissions/e1518.cs>)
58+
- [e1518.java](<../my-submissions/e1518.java>)
59+
- [e1518.js](<../my-submissions/e1518.js>)
60+
- [e1518.ts](<../my-submissions/e1518.ts>)
61+
### Python
62+
#### [e1518 v1 O(n) Daily.py](<../my-submissions/e1518 v1 O(n) Daily.py>)
63+
```Python
64+
class Solution:
65+
def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
66+
output = 0
67+
while numBottles >= numExchange :
68+
output += numBottles - numBottles % numExchange
69+
numBottles = numBottles % numExchange + numBottles // numExchange
70+
output += numBottles
71+
return output
72+
```
73+
74+
#### [e1518 v2 O(1).py](<../my-submissions/e1518 v2 O(1).py>)
75+
```Python
76+
class Solution:
77+
def numWaterBottles(self, numBottles: int, numExchange: int) -> int:
78+
return numBottles + (numBottles - 1) // (numExchange - 1)
79+
80+
```
81+
82+
### C
83+
#### [e1518.c](<../my-submissions/e1518.c>)
84+
```C
85+
int numWaterBottles(int numBottles, int numExchange) {
86+
return numBottles + (numBottles - 1) / (numExchange - 1);
87+
}
88+
```
89+
90+
### C++
91+
#### [e1518.cpp](<../my-submissions/e1518.cpp>)
92+
```C++
93+
class Solution {
94+
public:
95+
int numWaterBottles(int numBottles, int numExchange) {
96+
return numBottles + (numBottles - 1) / (numExchange - 1);
97+
}
98+
};
99+
```
100+
101+
### C#
102+
#### [e1518.cs](<../my-submissions/e1518.cs>)
103+
```C#
104+
public class Solution {
105+
public int NumWaterBottles(int numBottles, int numExchange) {
106+
return numBottles + (numBottles - 1) / (numExchange - 1);
107+
}
108+
}
109+
```
110+
111+
### Java
112+
#### [e1518.java](<../my-submissions/e1518.java>)
113+
```Java
114+
class Solution {
115+
public int numWaterBottles(int numBottles, int numExchange) {
116+
return numBottles + (numBottles - 1) / (numExchange - 1);
117+
}
118+
}
119+
```
120+
121+
### JavaScript
122+
#### [e1518.js](<../my-submissions/e1518.js>)
123+
```JavaScript
124+
/**
125+
* @param {number} numBottles
126+
* @param {number} numExchange
127+
* @return {number}
128+
*/
129+
var numWaterBottles = function(numBottles, numExchange) {
130+
return numBottles + Math.floor((numBottles - 1) / (numExchange - 1));
131+
};
132+
```
133+
134+
### TypeScript
135+
#### [e1518.ts](<../my-submissions/e1518.ts>)
136+
```TypeScript
137+
function numWaterBottles(numBottles: number, numExchange: number): number {
138+
return numBottles + Math.floor((numBottles - 1) / (numExchange - 1));
139+
};
140+
```
141+

markdowns/by_topic/Array.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
| 807 | [Max Increase to Keep City Skyline](<https://leetcode.com/problems/max-increase-to-keep-city-skyline>) | Medium | | [solution](<../_807. Max Increase to Keep City Skyline.md>) | java | Jun 22, 2024 |
7777
| 817 | [Linked List Components](<https://leetcode.com/problems/linked-list-components>) | Medium | | [solution](<../_817. Linked List Components.md>) | java | Jul 04, 2024 |
7878
| 826 | [Most Profit Assigning Work](<https://leetcode.com/problems/most-profit-assigning-work>) | Medium | Daily | [solution](<../_826. Most Profit Assigning Work.md>) | py | Jun 17, 2024 |
79-
| 846 | [Hand of Straights](<https://leetcode.com/problems/hand-of-straights>) | Medium | N150, Daily | [solution](<../_846. Hand of Straights.md>) | py | Jun 06, 2024 |
79+
| 846 | [Hand of Straights](<https://leetcode.com/problems/hand-of-straights>) | Medium | Daily, N150 | [solution](<../_846. Hand of Straights.md>) | py | Jun 06, 2024 |
8080
| 848 | [Shifting Letters](<https://leetcode.com/problems/shifting-letters>) | Medium | | [solution](<../_848. Shifting Letters.md>) | py | Jun 29, 2024 |
8181
| 849 | [Maximize Distance to Closest Person](<https://leetcode.com/problems/maximize-distance-to-closest-person>) | Medium | | [solution](<../_849. Maximize Distance to Closest Person.md>) | py | Jun 29, 2024 |
8282
| 853 | [Car Fleet](<https://leetcode.com/problems/car-fleet>) | Medium | N150 | [solution](<../_853. Car Fleet.md>) | py | Jun 13, 2024 |
@@ -94,7 +94,7 @@
9494
| 994 | [Rotting Oranges](<https://leetcode.com/problems/rotting-oranges>) | Medium | N150 | [solution](<../_994. Rotting Oranges.md>) | py | Jun 14, 2024 |
9595
| 995 | [Minimum Number of K Consecutive Bit Flips](<https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips>) | Hard | Daily | [solution](<../_995. Minimum Number of K Consecutive Bit Flips.md>) | py, c | Jun 23, 2024 |
9696
| 1002 | [Find Common Characters](<https://leetcode.com/problems/find-common-characters>) | Easy | Daily | [solution](<../_1002. Find Common Characters.md>) | py | Jun 04, 2024 |
97-
| 1008 | [Construct Binary Search Tree from Preorder Traversal](<https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal>) | Medium | | [solution](<../_1008. Construct Binary Search Tree from Preorder Traversal.md>) | cpp, java, c | Jun 26, 2024 |
97+
| 1008 | [Construct Binary Search Tree from Preorder Traversal](<https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal>) | Medium | | [solution](<../_1008. Construct Binary Search Tree from Preorder Traversal.md>) | java, c, cpp | Jun 26, 2024 |
9898
| 1018 | [Binary Prefix Divisible By 5](<https://leetcode.com/problems/binary-prefix-divisible-by-5>) | Easy | | [solution](<../_1018. Binary Prefix Divisible By 5.md>) | py | Jul 04, 2024 |
9999
| 1019 | [Next Greater Node In Linked List](<https://leetcode.com/problems/next-greater-node-in-linked-list>) | Medium | | [solution](<../_1019. Next Greater Node In Linked List.md>) | py | Jun 21, 2024 |
100100
| 1020 | [Number of Enclaves](<https://leetcode.com/problems/number-of-enclaves>) | Medium | | [solution](<../_1020. Number of Enclaves.md>) | py | Jun 26, 2024 |
@@ -127,7 +127,7 @@
127127
| 1481 | [Least Number of Unique Integers after K Removals](<https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals>) | Medium | | [solution](<../_1481. Least Number of Unique Integers after K Removals.md>) | py | Jun 15, 2024 |
128128
| 1482 | [Minimum Number of Days to Make m Bouquets](<https://leetcode.com/problems/minimum-number-of-days-to-make-m-bouquets>) | Medium | | [solution](<../_1482. Minimum Number of Days to Make m Bouquets.md>) | py | Jun 18, 2024 |
129129
| 1502 | [Can Make Arithmetic Progression From Sequence](<https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence>) | Easy | | [solution](<../_1502. Can Make Arithmetic Progression From Sequence.md>) | py, c | Jun 04, 2024 |
130-
| 1509 | [Minimum Difference Between Largest and Smallest Value in Three Moves](<https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves>) | Medium | Daily | [solution](<../_1509. Minimum Difference Between Largest and Smallest Value in Three Moves.md>) | py, cpp, java, c | Jul 02, 2024 |
130+
| 1509 | [Minimum Difference Between Largest and Smallest Value in Three Moves](<https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves>) | Medium | Daily | [solution](<../_1509. Minimum Difference Between Largest and Smallest Value in Three Moves.md>) | py, java, c, cpp | Jul 02, 2024 |
131131
| 1535 | [Find the Winner of an Array Game](<https://leetcode.com/problems/find-the-winner-of-an-array-game>) | Medium | | [solution](<../_1535. Find the Winner of an Array Game.md>) | py | Jun 08, 2024 |
132132
| 1550 | [Three Consecutive Odds](<https://leetcode.com/problems/three-consecutive-odds>) | Easy | Daily | [solution](<../_1550. Three Consecutive Odds.md>) | py, c | Jun 30, 2024 |
133133
| 1552 | [Magnetic Force Between Two Balls](<https://leetcode.com/problems/magnetic-force-between-two-balls>) | Medium | Daily | [solution](<../_1552. Magnetic Force Between Two Balls.md>) | py | Jun 20, 2024 |
@@ -163,7 +163,7 @@
163163
| 2225 | [Find Players With Zero or One Losses](<https://leetcode.com/problems/find-players-with-zero-or-one-losses>) | Medium | | [solution](<../_2225. Find Players With Zero or One Losses.md>) | java | Jun 24, 2024 |
164164
| 2248 | [Intersection of Multiple Arrays](<https://leetcode.com/problems/intersection-of-multiple-arrays>) | Easy | | [solution](<../_2248. Intersection of Multiple Arrays.md>) | py | May 29, 2024 |
165165
| 2258 | [Escape the Spreading Fire](<https://leetcode.com/problems/escape-the-spreading-fire>) | Hard | | [solution](<../_2258. Escape the Spreading Fire.md>) | py | Jun 14, 2024 |
166-
| 2317 | [Maximum XOR After Operations ](<https://leetcode.com/problems/maximum-xor-after-operations>) | Medium | | [solution](<../_2317. Maximum XOR After Operations .md>) | py, cpp, java, c | Jun 24, 2024 |
166+
| 2317 | [Maximum XOR After Operations ](<https://leetcode.com/problems/maximum-xor-after-operations>) | Medium | | [solution](<../_2317. Maximum XOR After Operations .md>) | py, java, c, cpp | Jun 24, 2024 |
167167
| 2352 | [Equal Row and Column Pairs](<https://leetcode.com/problems/equal-row-and-column-pairs>) | Medium | | [solution](<../_2352. Equal Row and Column Pairs.md>) | py | Jun 26, 2024 |
168168
| 2365 | [Task Scheduler II](<https://leetcode.com/problems/task-scheduler-ii>) | Medium | | [solution](<../_2365. Task Scheduler II.md>) | py | Jun 29, 2024 |
169169
| 2389 | [Longest Subsequence With Limited Sum](<https://leetcode.com/problems/longest-subsequence-with-limited-sum>) | Easy | | [solution](<../_2389. Longest Subsequence With Limited Sum.md>) | py | May 31, 2024 |

markdowns/by_topic/Binary Search Tree.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
| 450 | [Delete Node in a BST](<https://leetcode.com/problems/delete-node-in-a-bst>) | Medium | | [solution](<../_450. Delete Node in a BST.md>) | py | Jun 28, 2024 |
1616
| 703 | [Kth Largest Element in a Stream](<https://leetcode.com/problems/kth-largest-element-in-a-stream>) | Easy | N150 | [solution](<../_703. Kth Largest Element in a Stream.md>) | py | Jul 04, 2024 |
1717
| 776 | [Split BST](<https://leetcode.com/problems/split-bst>) | Medium | Weekly Premium | [solution](<../_776. Split BST.md>) | py | Jun 28, 2024 |
18-
| 1008 | [Construct Binary Search Tree from Preorder Traversal](<https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal>) | Medium | | [solution](<../_1008. Construct Binary Search Tree from Preorder Traversal.md>) | cpp, java, c | Jun 26, 2024 |
18+
| 1008 | [Construct Binary Search Tree from Preorder Traversal](<https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal>) | Medium | | [solution](<../_1008. Construct Binary Search Tree from Preorder Traversal.md>) | java, c, cpp | Jun 26, 2024 |
1919
| 1038 | [Binary Search Tree to Greater Sum Tree](<https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree>) | Medium | Daily | [solution](<../_1038. Binary Search Tree to Greater Sum Tree.md>) | c | Jun 23, 2024 |
2020
| 1305 | [All Elements in Two Binary Search Trees](<https://leetcode.com/problems/all-elements-in-two-binary-search-trees>) | Medium | | [solution](<../_1305. All Elements in Two Binary Search Trees.md>) | java | Jun 24, 2024 |
2121
| 1382 | [Balance a Binary Search Tree](<https://leetcode.com/problems/balance-a-binary-search-tree>) | Medium | Daily | [solution](<../_1382. Balance a Binary Search Tree.md>) | py | Jun 25, 2024 |

0 commit comments

Comments
 (0)