Skip to content

Commit 6ca0b18

Browse files
updating all READMEs
1 parent cd0978b commit 6ca0b18

File tree

10 files changed

+462
-13
lines changed

10 files changed

+462
-13
lines changed

.dev/logs.json

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@
341341
"EditDistance.cpp": "b4bd72e93856ab894bf96b1cb40a481ffca34a55fd05bb108db05ef85ebe99a8",
342342
"EditDistance.java": "b6f792cc2b8699d82eb3cf63c8703f2e088b48a52643f0857d054dec3b6cf87d",
343343
"edit_distance.py": "dc97b086e122419fe3fe563f202ff1262f8f5597cc234468d521866782a45bd5",
344-
"edit_distance.rs": "dea16c9d3cffaf7dcd7a6b80a1fef890f8b5c75859e3fd5240b7e90b1c355796"
344+
"edit_distance.rs": "dea16c9d3cffaf7dcd7a6b80a1fef890f8b5c75859e3fd5240b7e90b1c355796",
345+
"edit_distance.go": "cba58889fffe6afc44bac247ce3c99058da4af1955af7abdd0c395958d485a48"
345346
}
346347
},
347348
"73": {
@@ -1808,8 +1809,10 @@
18081809
"sols": {}
18091810
},
18101811
"401": {
1811-
"len": 0,
1812-
"sols": {}
1812+
"len": 2,
1813+
"sols": {
1814+
"binary_watch.rs": "fbdef0b2f69b0b471006bb8099f629b30f78a2fada98ae2e990ac4de81184e61"
1815+
}
18131816
},
18141817
"402": {
18151818
"len": 0,
@@ -1854,16 +1857,20 @@
18541857
"sols": {}
18551858
},
18561859
"412": {
1857-
"len": 0,
1858-
"sols": {}
1860+
"len": 2,
1861+
"sols": {
1862+
"fizz_buzz.rs": "e39f752ba38830fe2affcfb943ffe1999d9cb3fc702220af257270cb69ebf319"
1863+
}
18591864
},
18601865
"413": {
18611866
"len": 0,
18621867
"sols": {}
18631868
},
18641869
"414": {
1865-
"len": 0,
1866-
"sols": {}
1870+
"len": 2,
1871+
"sols": {
1872+
"third_max_num.rs": "b559175ad3d9e03bdb97c798f77065b009c23203602d6da1b259fb507fd7d8ff"
1873+
}
18671874
},
18681875
"415": {
18691876
"len": 0,
@@ -8979,8 +8986,10 @@
89798986
"sols": {}
89808987
},
89818988
"2176": {
8982-
"len": 0,
8983-
"sols": {}
8989+
"len": 2,
8990+
"sols": {
8991+
"count_equal_and_divisible_pairs_in_an_array.rs": "24bf5162c8db157e697da4501d67bd1f3c5d4c995d3a89ac64f23a7abdb1afb6"
8992+
}
89848993
},
89858994
"2177": {
89868995
"len": 0,
@@ -9985,8 +9994,10 @@
99859994
"sols": {}
99869995
},
99879996
"2427": {
9988-
"len": 0,
9989-
"sols": {}
9997+
"len": 2,
9998+
"sols": {
9999+
"num_of_common_factors.rs": "e0f29658a195497d4df9d15abf7e5897bae7be7c19df71c2a6f3920db03dd568"
10000+
}
999010001
},
999110002
"2428": {
999210003
"len": 0,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[**_Rejection Sampling_**][rejection sampling]   
9696
[**_Biconnected Component_**][biconnected component]
9797

98-
### **Total Problems Solved: _134_**
98+
### **Total Problems Solved: _139_**
9999

100100
---
101101

TOPICWISE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
| **0322** | [Coin Change][322] | Array, DP, BFS | ![][medium] | |
4949
| **0349** | [Intersection of Two Arrays][349] | Array, Hash Table, 2P, BS, Sorting | ![][easy] | |
5050
| **0350** | [Intersection of Two Arrays II][350] | Array, Hash Table, 2P, BS, Sorting | ![][easy] | |
51+
| **0414** | [Third Maximum Number][414] | Array, Sorting | ![][easy] | |
5152
| **0442** | [Find All Duplicates][442] | Array, Hash Table | ![][medium] | |
5253
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
5354
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
@@ -65,6 +66,7 @@
6566
| **1498** | [Number of Subsequences That Satisfy the Given Sum Condition][1498] | Array, 2P, BS, Sorting | ![][medium] | |
6667
| **1537** | [Get the Maximum Score][1537] | Array, Two Pointer, DP, Greedy | ![][hard] | |
6768
| **1580** | [Shuffle the Array][1580] | Array | ![][easy] | |
69+
| **2176** | [Count Equal and Divisible Pairs in an Array][2176] | Array | ![][easy] | |
6870

6971
<!---------------------------------{ Solution Table }-------------------------->
7072

@@ -90,6 +92,7 @@
9092
| **0387** | [First Unique Character in a String][387] | Hash Table, String, Q, Counting | ![][easy] | |
9193
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
9294
| **0392** | [Is Subsequence][392] | 2P, String, DP | ![][easy] | |
95+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
9396
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
9497
| **0516** | [Longest Palindromic Subsequence][516] | String, DP | ![][medium] | |
9598
| **0541** | [Reverse String II][541] | Two Pointers, String | ![][easy] | |
@@ -182,6 +185,7 @@
182185
| **0326** | [Power of Three][326] | Math, Recursion | ![][easy] | |
183186
| **0342** | [Power of Four][342] | Math, Bit Manip, Recursion | ![][easy] | |
184187
| **0367** | [Valid Perfect Square][367] | Math, Binary Search | ![][easy] | |
188+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
185189
| **0445** | [Add Two Numbers II][445] | Linked List, Math, Stack | ![][medium] | |
186190
| **0509** | [Fibonacci Number][509] | Math, Recursion, DP, Memoization | ![][easy] | |
187191
| **1232** | [Check If It Is a Straight Line][1232] | Array, Math, Geometry | ![][easy] | |
@@ -202,6 +206,7 @@
202206
| **0349** | [Intersection of Two Arrays][349] | Array, Hash Table, 2P, BS, Sorting | ![][easy] | |
203207
| **0350** | [Intersection of Two Arrays II][350] | Array, Hash Table, 2P, BS, Sorting | ![][easy] | |
204208
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
209+
| **0414** | [Third Maximum Number][414] | Array, Sorting | ![][easy] | |
205210
| **0502** | [IPO][502] | Array, Greedy, Sorting, Heap (Priority Queue) | ![][hard] | |
206211
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
207212
| **0888** | [Fair Candy Swap][888] | Array, Hash Table, Binary Search, Sorting | ![][easy] | |
@@ -402,6 +407,7 @@
402407
| **0338** | [Counting Bits][338] | DP, Bit Manip | ![][easy] | |
403408
| **0342** | [Power of Four][342] | Math, Bit Manip, Recursion | ![][easy] | |
404409
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
410+
| **0401** | [Binary Watch][401] | Backtracking, Bit Manip | ![][easy] | |
405411
| **1461** | [Check If a String Contains All Binary Codes of Size K][1461] | String, Hash Table, Bit Manipulation | ![][medium] | |
406412

407413
<!---------------------------------{ Solution Table }-------------------------->
@@ -454,6 +460,7 @@
454460
| :------: | :---------------: | :---------------------------------: | :--------: | :----: |
455461
| **0067** | [Add Binary][67] | Math, String, Bit Manip, Simulation | ![][easy] | |
456462
| **0258** | [Add Digits][258] | Math, Simulation, Number Theory | ![][easy] | |
463+
| **0412** | [Fizz Buzz][412] | Math, String, Simulation | ![][easy] | |
457464

458465
<!---------------------------------{ Solution Table }-------------------------->
459466

@@ -466,6 +473,7 @@
466473
| **0051** | [N-Queens][51] | Array, Backtracking | ![][hard] | |
467474
| **0078** | [Subsets][78] | Array, Backtracking, Bit Manip | ![][medium] | |
468475
| **0257** | [Binary Tree Paths][257] | String, Backtracking, Tree, Depth-First Search, Binary Tree | ![][easy] | |
476+
| **0401** | [Binary Watch][401] | Backtracking, Bit Manip | ![][easy] | |
469477

470478
<!---------------------------------{ Solution Table }-------------------------->
471479

@@ -974,7 +982,10 @@
974982
[387]: ./src/0301-0400/387%20-%20First%20Unique%20Character%20in%20a%20String/
975983
[389]: ./src/0301-0400/389%20-%20Find%20the%20Difference/
976984
[392]: ./src/0301-0400/392%20-%20Is%20Subsequence/
985+
[401]: ./src/0401-0500/401%20-%20Binary%20Watch/
977986
[404]: ./src/0401-0500/404%20-%20Sum%20of%20Left%20Leaves/
987+
[412]: ./src/0401-0500/412%20-%20Fizz%20Buzz/
988+
[414]: ./src/0401-0500/414%20-%20Third%20Maximum%20Number/
978989
[438]: ./src/0401-0500/438%20-%20Find%20All%20Anagrams%20in%20a%20String/
979990
[442]: ./src/0401-0500/442%20-%20Find%20All%20Duplicates%20in%20an%20Array/
980991
[445]: ./src/0401-0500/445%20-%20Add%20Two%20Numbers%20II/
@@ -1010,6 +1021,7 @@
10101021
[1580]: ./src/1401-1500/1470%20-%20Shuffle%20the%20Array/
10111022
[1630]: ./src/1501-1600/1523.%20Count%20Odd%20Numbers%20in%20an%20Interval%20Range/
10121023
[1957]: ./src/1901-2000/1957%20-%20Delete%20Characters%20to%20Make%20Fancy%20String/
1024+
[2176]: ./src/2101-2200/2176%20-%20Count%20Equal%20and%20Divisible%20Pairs%20in%20an%20Array/
10131025
[2236]: ./src/2201-2300/2236%20-%20Root%20Equals%20Sum%20of%20Children/
10141026

10151027
<!----------------------------------{ Labels }--------------------------------->

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ It might take some time to reflect changes from the repository.
103103
[**_Rejection Sampling_**][rejection sampling] &nbsp;&nbsp;
104104
[**_Biconnected Component_**][biconnected component]
105105

106-
### **Total Problems Solved: _134_**
106+
### **Total Problems Solved: _139_**
107107

108108
## Contributors
109109

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# 401. Binary Watch [![share]](https://leetcode.com/problems/binary-watch/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.</p>
8+
<ul>
9+
<li>For example, the below binary watch reads <code>"4:51"</code>.</li>
10+
</ul>
11+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/04/08/binarywatch.jpg" style="width: 500px; height: 500px;"/></p>
12+
<p>Given an integer <code>turnedOn</code> which represents the number of LEDs that are currently on (ignoring the PM), return <em>all possible times the watch could represent</em>. You may return the answer in <strong>any order</strong>.</p>
13+
<p>The hour must not contain a leading zero.</p>
14+
<ul>
15+
<li>For example, <code>"01:00"</code> is not valid. It should be <code>"1:00"</code>.</li>
16+
</ul>
17+
<p>The minute must be consist of two digits and may contain a leading zero.</p>
18+
<ul>
19+
<li>For example, <code>"10:2"</code> is not valid. It should be <code>"10:02"</code>.</li>
20+
</ul>
21+
<p> </p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
```
25+
Input: turnedOn = 1
26+
Output: ["0:01","0:02","0:04","0:08","0:16","0:32","1:00","2:00","4:00","8:00"]
27+
```
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
```
32+
Input: turnedOn = 9
33+
Output: []
34+
```
35+
36+
<p> </p>
37+
<p><strong>Constraints:</strong></p>
38+
<ul>
39+
<li><code>0 &lt;= turnedOn &lt;= 10</code></li>
40+
</ul>
41+
42+
<details>
43+
<summary>
44+
45+
#### _Click to open Hints_
46+
47+
</summary>
48+
49+
- Simplify by seeking for solutions that involve comparing bit counts.
50+
- Consider calculating all possible times for comparison purposes.
51+
52+
</details>
53+
54+
## Solutions
55+
56+
### [_Rust_](binary_watch.rs)
57+
58+
```rs [Rust]
59+
impl Solution {
60+
pub fn read_binary_watch(turned_on: i32) -> Vec<String> {
61+
let mut res = Vec::new();
62+
63+
// 12 hours, 60 minutes
64+
// here we use 0_i32 to avoid the warning of type inference
65+
for i in 0_i32..12 {
66+
for j in 0_i32..60 {
67+
// if the sum of the number of 1s in the binary representation
68+
// of the hour and minute is equal to turned_on,
69+
// then the time is added to the res
70+
if i.count_ones() + j.count_ones() == turned_on as u32 {
71+
res.push(format!("{}:{:02}", i, j));
72+
}
73+
}
74+
}
75+
76+
res
77+
}
78+
}
79+
80+
```
81+
82+
### [_..._]()
83+
84+
```
85+
86+
```
87+
88+
<!----------------------------------{ link }--------------------------------->
89+
90+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
91+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
92+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
93+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# 412. Fizz Buzz [![share]](https://leetcode.com/problems/fizz-buzz/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer <code>n</code>, return <em>a string array </em><code>answer</code><em> (<strong>1-indexed</strong>) where</em>:</p>
8+
<ul>
9+
<li><code>answer[i] == "FizzBuzz"</code> if <code>i</code> is divisible by <code>3</code> and <code>5</code>.</li>
10+
<li><code>answer[i] == "Fizz"</code> if <code>i</code> is divisible by <code>3</code>.</li>
11+
<li><code>answer[i] == "Buzz"</code> if <code>i</code> is divisible by <code>5</code>.</li>
12+
<li><code>answer[i] == i</code> (as a string) if none of the above conditions are true.</li>
13+
</ul>
14+
<p> </p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
17+
```
18+
Input: n = 3
19+
Output: ["1","2","Fizz"]
20+
```
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
```
25+
Input: n = 5
26+
Output: ["1","2","Fizz","4","Buzz"]
27+
```
28+
29+
<p><strong class="example">Example 3:</strong></p>
30+
31+
```
32+
Input: n = 15
33+
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
34+
```
35+
36+
<p> </p>
37+
<p><strong>Constraints:</strong></p>
38+
<ul>
39+
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
40+
</ul>
41+
42+
## Solutions
43+
44+
### [_Rust_](fizz_buzz.rs)
45+
46+
```rs [Rust]
47+
impl Solution {
48+
pub fn fizz_buzz(n: i32) -> Vec<String> {
49+
let mut res = Vec::new();
50+
51+
for i in 1..=n {
52+
// same as divisible by 3 and 5
53+
if i % 15 == 0 {
54+
res.push("FizzBuzz".to_string());
55+
} else if i % 3 == 0 {
56+
res.push("Fizz".to_string());
57+
} else if i % 5 == 0 {
58+
res.push("Buzz".to_string());
59+
} else {
60+
res.push(i.to_string());
61+
}
62+
}
63+
64+
res
65+
}
66+
}
67+
68+
```
69+
70+
### [_..._]()
71+
72+
```
73+
74+
```
75+
76+
<!----------------------------------{ link }--------------------------------->
77+
78+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
79+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
80+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
81+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

0 commit comments

Comments
 (0)