Skip to content

Commit 5dad097

Browse files
committed
Formatting update
1 parent da7910e commit 5dad097

File tree

94 files changed

+642
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+642
-586
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
This repo is a collection of my LeetCode solutions, primarily written in Python, Java, and C. On any page, `click the main title` to be redirected to the official `LeetCode` page for the question, topic, list, etc. See the `Additional Categories` section for pages that group questions by different criteria -- e.g. by their *related topics*.
88

99

10+
------
11+
1012
## Category Notes
1113
1. **Daily** - Daily challenge questions that were done on the day of
1214
2. **Weekly Premium** - Weekly premium questions that were done on week of

markdowns/Questions_By_Code_Length.md

+29-29
Large diffs are not rendered by default.

markdowns/_1002. Find Common Characters.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : June 04, 2024*
66
>
7-
> *Last updated : July 01, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -27,7 +27,6 @@
2727
# Daily
2828
# Doing this with bad wifi so I can barely submit so idc about efficiency lol
2929

30-
3130
class Solution:
3231
def commonChars(self, words: List[str]) -> List[str]:
3332
cnter = []

markdowns/_1184. Distance Between Bus Stops.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : May 31, 2024*
66
>
7-
> *Last updated : July 01, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,18 +18,22 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Notes
23+
> A bit bulky but did it for the theoretical runtime savings. Still O(n) but
24+
> can save on the additional calclations if one direction is significantly
25+
> shorter than the other by not having to have the additional addition operations.
26+
> ```
27+
>
28+
29+
------
30+
2131
## Solutions
2232
2333
- [e1184.py](<../my-submissions/e1184.py>)
2434
### Python
2535
#### [e1184.py](<../my-submissions/e1184.py>)
2636
```Python
27-
''' Notes
28-
A bit bulky but did it for the theoretical runtime savings. Still O(n) but
29-
can save on the additional calclations if one direction is significantly
30-
shorter than the other by not having to have the additional addition operations.
31-
'''
32-
3337
class Solution:
3438
def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
3539
counter, clockwise = start, start

markdowns/_1404. Number of Steps to Reduce a Number in Binary Representation to One.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : May 29, 2024*
66
>
7-
> *Last updated : July 01, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,18 +18,23 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Ideas
23+
> We can just go right to left.
24+
> - If rightmost bit is 0, +1 step and shift position left 1
25+
> - If 1, +1 step and have a "carry" for the next
26+
> ```
27+
>
28+
>
29+
30+
------
31+
2132
## Solutions
2233
2334
- [m1404 Daily.py](<../my-submissions/m1404 Daily.py>)
2435
### Python
2536
#### [m1404 Daily.py](<../my-submissions/m1404 Daily.py>)
2637
```Python
27-
''' Ideas
28-
We can just go right to left.
29-
- If rightmost bit is 0, +1 step and shift position left 1
30-
- If 1, +1 step and have a "carry" for the next
31-
'''
32-
3338
class Solution:
3439
def numSteps(self, s: str) -> int:
3540
counter = 0

markdowns/_1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : June 22, 2024*
66
>
7-
> *Last updated : June 22, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,20 +18,23 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Notes
23+
> We can store the max and min value going in each direction
24+
>
25+
> Option 1: Brute force all options
26+
> Option 2: Sliding window
27+
> If we're above limit, we shift whichever pointer is leftmost += 1
28+
> ```
29+
30+
------
31+
2132
## Solutions
2233
2334
- [m1438 Daily.java](<../my-submissions/m1438 Daily.java>)
2435
### Java
2536
#### [m1438 Daily.java](<../my-submissions/m1438 Daily.java>)
2637
```Java
27-
/** Notes
28-
We can store the max and min value going in each direction
29-
30-
Option 1: Brute force all options
31-
Option 2: Sliding window
32-
If we're above limit, we shift whichever pointer is leftmost += 1
33-
*/
34-
3538
class Solution {
3639
public int longestSubarray(int[] nums, int limit) {
3740
int output = 0;

markdowns/_1442. Count Triplets That Can Form Two Arrays of Equal XOR.md

+28-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : May 29, 2024*
66
>
7-
> *Last updated : July 01, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,36 +18,39 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Notes
23+
> Negation of XOR is Biconditional
24+
> i.e. p <-> q
25+
> (p -> q) and (q -> p)
26+
> (!p or q) and (!q or p)
27+
> (!p and !q) or (p and q)
28+
> p == q
29+
>
30+
>
31+
> 1^0 --> 1 --> --> 1^0 --> 1
32+
> 1^1 --> 0 --> --> 0^1 --> 1
33+
> 0^0 --> 0 --> --> 0^0 --> 0
34+
> 0^1 --> 1 --> --> 1^1 --> 0
35+
>
36+
> XORing by the same value again reverses the result!
37+
>
38+
> Since 0 <= i < j <= k < arr.len --> k-i+1 >= 2
39+
>
40+
> If two arrays XOR together to get 0, then the two individual sections should have
41+
> an XOR that equal each other.
42+
>
43+
> That is, XOR(arr1) == XOR(arr2) so that XOR(arr1, arr2) == 0
44+
>
45+
46+
------
47+
2148
## Solutions
2249
2350
- [m1442 Daily.py](<../my-submissions/m1442 Daily.py>)
2451
### Python
2552
#### [m1442 Daily.py](<../my-submissions/m1442 Daily.py>)
2653
```Python
27-
''' Notes
28-
Negation of XOR is Biconditional
29-
i.e. p <-> q
30-
(p -> q) and (q -> p)
31-
(!p or q) and (!q or p)
32-
(!p and !q) or (p and q)
33-
p == q
34-
35-
36-
1^0 --> 1 --> --> 1^0 --> 1
37-
1^1 --> 0 --> --> 0^1 --> 1
38-
0^0 --> 0 --> --> 0^0 --> 0
39-
0^1 --> 1 --> --> 1^1 --> 0
40-
41-
XORing by the same value again reverses the result!
42-
43-
Since 0 <= i < j <= k < arr.len --> k-i+1 >= 2
44-
45-
If two arrays XOR together to get 0, then the two individual sections should have
46-
an XOR that equal each other.
47-
48-
That is, XOR(arr1) == XOR(arr2) so that XOR(arr1, arr2) == 0
49-
'''
50-
5154
class Solution:
5255
def countTriplets(self, arr: List[int]) -> int:
5356
counter = 0

markdowns/_1482. Minimum Number of Days to Make m Bouquets.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : June 18, 2024*
66
>
7-
> *Last updated : June 18, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,18 +18,22 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Notes
23+
> This seems a lot like merge intervals where we need to find how many days till
24+
> sum(interval - remainder for interval in intervals) >= m * k
25+
> ```
26+
>
27+
28+
------
29+
2130
## Solutions
2231
2332
- [m1482 Dailly.py](<../my-submissions/m1482 Dailly.py>)
2433
- [m1482 v2 Removed Helper.py](<../my-submissions/m1482 v2 Removed Helper.py>)
2534
### Python
2635
#### [m1482 Dailly.py](<../my-submissions/m1482 Dailly.py>)
2736
```Python
28-
''' Notes
29-
This seems a lot like merge intervals where we need to find how many days till
30-
sum(interval - remainder for interval in intervals) >= m * k
31-
'''
32-
3337
class Solution:
3438
def minDays(self, bloomDay: List[int], m: int, k: int) -> int:
3539
@@ -80,11 +84,6 @@ class Solution:
8084
8185
#### [m1482 v2 Removed Helper.py](<../my-submissions/m1482 v2 Removed Helper.py>)
8286
```Python
83-
''' Notes
84-
This seems a lot like merge intervals where we need to find how many days till
85-
sum(interval - remainder for interval in intervals) >= m * k
86-
'''
87-
8887
class Solution:
8988
def minDays(self, bloomDay: List[int], m: int, k: int) -> int:
9089

markdowns/_1551. Minimum Operations to Make Array Equal.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : June 12, 2024*
66
>
7-
> *Last updated : July 01, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,6 +18,24 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
>
22+
> ```
23+
> sum = (2 * n + 2) * n // 2
24+
> mean = (2 * n + 2) / 2
25+
> margineToMove = sum(2n+1 - ((2 * n + 2) / 2))
26+
> = sum(2n+1 - (n+1))
27+
> = sum(n)
28+
> = (1 + n) * n // 2
29+
> number of steps = margineToMove / 2
30+
> = (1 + n) * n // 2 // 2
31+
> = (n^2 + 1) // 4
32+
> = n^2 // 4
33+
> = n ** 2 // 4
34+
>
35+
> ```
36+
37+
------
38+
2139
## Solutions
2240
2341
- [m1551 v2.c](<../my-submissions/m1551 v2.c>)
@@ -78,17 +96,6 @@ class Solution {
7896
```Python
7997
class Solution:
8098
def minOperations(self, n: int) -> int:
81-
# sum = (2 * n + 2) * n // 2
82-
# mean = (2 * n + 2) / 2
83-
# margineToMove = sum(2n+1 - ((2 * n + 2) / 2))
84-
# = sum(2n+1 - (n+1))
85-
# = sum(n)
86-
# = (1 + n) * n // 2
87-
# number of steps = margineToMove / 2
88-
# = (1 + n) * n // 2 // 2
89-
# = (n^2 + 1) // 4
90-
# = n^2 // 4
91-
# = n ** 2 // 4
9299
return n ** 2 // 4
93100
```
94101

markdowns/_1552. Magnetic Force Between Two Balls.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> *First completed : June 20, 2024*
66
>
7-
> *Last updated : June 20, 2024*
7+
> *Last updated : July 03, 2024*
88
99

1010
------
@@ -18,20 +18,23 @@
1818

1919
*To see the question prompt, click the title.*
2020

21+
> ```
22+
> Notes
23+
> In essence, we have x positions and m balls, and we need to find AN ideal
24+
> way where we can place the m balls into m positions so that the min distance
25+
> between the balls is minimized
26+
>
27+
> The ideal case will be (max(position) - min(position)) / (m - 1)
28+
> ```
29+
30+
------
31+
2132
## Solutions
2233
2334
- [m1552 Daily.py](<../my-submissions/m1552 Daily.py>)
2435
### Python
2536
#### [m1552 Daily.py](<../my-submissions/m1552 Daily.py>)
2637
```Python
27-
''' Notes
28-
In essence, we have x positions and m balls, and we need to find AN ideal
29-
way where we can place the m balls into m positions so that the min distance
30-
between the balls is minimized
31-
32-
The ideal case will be (max(position) - min(position)) / (m - 1)
33-
'''
34-
3538
class Solution:
3639
def maxDistance(self, position: List[int], m: int) -> int:
3740
position.sort()

0 commit comments

Comments
 (0)