Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions books/July_2025.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Explanation:
- Query [1,1]: Station 1 is offline and there are no other stations in its grid, so the result is -1.

**Constraints**
```text
```tex
1 <= c <= 10^5
0 <= n == connections.length <= min(10^5, c * (c - 1) / 2)
connections[i].length == 2
Expand Down Expand Up @@ -346,7 +346,7 @@ There is only one horizontal trapezoid that can be formed.

**Constraints**

```text
```tex
4 <= points.length <= 10^5
-10^8 <= x_i, y_i <= 10^8
All points are pairwise distinct.
Expand Down Expand Up @@ -414,7 +414,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]]
- **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points.
- **Space Complexity:** O(N) for storing the groups.

```text
```tex
| Step | Operation | Count |
| ---- | ----------------- | ----- |
| 1 | Group points by y | N |
Expand Down
14 changes: 7 additions & 7 deletions books/Random.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ You are given two non-empty linked lists representing two non-negative integers.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:
```text
```tex
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Expand All @@ -98,7 +98,7 @@ Output: [8,9,9,9,0,0,0,1]
```

Constraints:
```text
```tex
The number of nodes in each linked list is in the range [1, 100].
0 <= Node.val <= 9
It is guaranteed that the list represents a number that does not have leading zeros.
Expand Down Expand Up @@ -1018,7 +1018,7 @@ word2: p q
merged: a p b q c d

**Constraints**
```text
```tex
- 1 <= word1.length, word2.length <= 100
- word1 and word2 consist of lowercase English letters.
```
Expand Down Expand Up @@ -1313,7 +1313,7 @@ Return the *sum* of the complete subset with the *maximum sum*.

**Constraints**

```text
```tex
1 <= n == nums.length <= 10^4
1 <= nums[i] <= 10^9
```
Expand Down Expand Up @@ -1432,7 +1432,7 @@ Explanation:
- Query [1,1]: Station 1 is offline and there are no other stations in its grid, so the result is -1.

**Constraints**
```text
```tex
1 <= c <= 10^5
0 <= n == connections.length <= min(10^5, c * (c - 1) / 2)
connections[i].length == 2
Expand Down Expand Up @@ -1721,7 +1721,7 @@ There is only one horizontal trapezoid that can be formed.

**Constraints**

```text
```tex
4 <= points.length <= 10^5
-10^8 <= x_i, y_i <= 10^8
All points are pairwise distinct.
Expand Down Expand Up @@ -1789,7 +1789,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]]
- **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points.
- **Space Complexity:** O(N) for storing the groups.

```text
```tex
| Step | Operation | Count |
| ---- | ----------------- | ----- |
| 1 | Group points by y | N |
Expand Down
6 changes: 3 additions & 3 deletions books/Visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ word2: p q
merged: a p b q c d

**Constraints**
```text
```tex
- 1 <= word1.length, word2.length <= 100
- word1 and word2 consist of lowercase English letters.
```
Expand Down Expand Up @@ -414,7 +414,7 @@ There is only one horizontal trapezoid that can be formed.

**Constraints**

```text
```tex
4 <= points.length <= 10^5
-10^8 <= x_i, y_i <= 10^8
All points are pairwise distinct.
Expand Down Expand Up @@ -482,7 +482,7 @@ Suppose points = [[1,0],[2,0],[3,0],[2,2],[3,2]]
- **Time Complexity:** O(N + K), where N is the number of points and K is the number of y-levels with at least 2 points.
- **Space Complexity:** O(N) for storing the groups.

```text
```tex
| Step | Operation | Count |
| ---- | ----------------- | ----- |
| 1 | Group points by y | N |
Expand Down
2 changes: 1 addition & 1 deletion data/book-sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"tags": [],
"problems": [
1, 2, 11, 12, 13, 14, 15, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 33, 34, 35, 36, 39, 42, 45, 46, 48, 49, 50, 52, 53, 54, 55, 56, 57,
58, 61, 63, 64, 66, 67, 68, 69, 70, 71, 73, 76, 77, 79, 80, 82, 86, 88, 92, 97, 98, 125, 138, 139, 141, 146, 148, 149, 150, 151, 153, 155, 162,
58, 61, 63, 64, 66, 67, 68, 69, 70, 71, 73, 76, 77, 79, 80, 82, 86, 88, 92, 97, 98, 125, 136, 138, 139, 141, 146, 148, 149, 150, 151, 153, 155, 162,
167, 169, 172, 173, 188, 189, 190, 191, 198, 199, 200, 201, 202, 205, 207, 208, 209, 210, 211, 212, 215, 217, 221, 222, 224, 226, 228, 230, 238,
242, 268, 274, 283, 289, 290, 295, 300, 334, 344, 345, 373, 380, 383, 392, 399, 427, 433, 443, 452, 502, 530, 605, 637, 643, 647, 739, 901, 909,
918, 1004, 1071, 1207, 1431, 1456, 1657, 1679, 1732, 1768, 1798, 1957, 1991, 2215, 2352, 2862, 3424, 3602, 3603, 3604, 3605, 3606, 3607, 3608,
Expand Down
4 changes: 2 additions & 2 deletions explanations/1/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can return the answer in any order.

Examples:

```text
```tex
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Expand All @@ -26,7 +26,7 @@ Output: [0,1]

Constraints:

```text
```tex
2 <= nums.length <= 10^4
-10^9 <= nums[i] <= 10^9
-10^9 <= target <= 10^9
Expand Down
2 changes: 1 addition & 1 deletion explanations/1071/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For two strings `s` and `t`, we say "t divides s" if and only if `s = t + t + ..
Given two strings `str1` and `str2`, return the largest string `x` such that `x` divides both `str1` and `str2`.

**Examples**
```text
```tex
Input: str1 = "ABCABC", str2 = "ABC"
Output: "ABC"

Expand Down
4 changes: 2 additions & 2 deletions explanations/125/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A phrase is a palindrome if, after converting all uppercase letters into lowerca
Given a string `s`, return `true` if it is a palindrome, or `false` otherwise.

**Examples**
```text
```tex
Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Expand All @@ -25,7 +25,7 @@ An empty string is a palindrome.
```

**Constraints:**
```text
```tex
1 <= s.length <= 2 * 10^5
s consists only of printable ASCII characters.
```
Expand Down
92 changes: 92 additions & 0 deletions explanations/136/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Given a **non-empty** array of integers `nums`, every element appears *twice* except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

**Example 1:**
```sh
Input: nums = [2,2,1]
Output: 1
```

**Example 2:**
```sh
Input: nums = [4,1,2,1,2]
Output: 4
```

**Example 3:**
```sh
Input: nums = [1]
Output: 1
```

**Constraints:**
- `1 <= nums.length <= 3 * 10^4`
- `-3 * 10^4 <= nums[i] <= 3 * 10^4`
- Each element in the array appears twice except for one element which appears only once.

## Explanation

### Strategy

This is a **bit manipulation problem** that requires finding the single element in an array where all other elements appear twice. The key insight is to use the XOR (exclusive or) operation, which has special properties that make it perfect for this problem.

**Key observations:**
- XOR of a number with itself is 0: `a ^ a = 0`
- XOR of a number with 0 is the number itself: `a ^ 0 = a`
- XOR is associative and commutative: `a ^ b ^ a = (a ^ a) ^ b = 0 ^ b = b`
- All elements appear twice except one, so XORing all elements will cancel out the pairs

**High-level approach:**
1. **Initialize result**: Start with `result = 0`
2. **XOR all elements**: Iterate through the array and XOR each element with the result
3. **Return result**: The final result will be the single number

### Steps

Let's break down the solution step by step:

**Step 1: Initialize result**
- Start with `result = 0`

**Step 2: XOR all elements**
For each number in the array:
- XOR the current number with the result: `result = result ^ num`
- This will cancel out pairs and leave the single number

**Step 3: Return the result**
- The final result is the single number

**Example walkthrough:**
Let's trace through the second example:

```sh
nums = [4,1,2,1,2]

Initial state:
result = 0

Step 1: result = 0 ^ 4 = 4

Step 2: result = 4 ^ 1 = 5

Step 3: result = 5 ^ 2 = 7

Step 4: result = 7 ^ 1 = 6

Step 5: result = 6 ^ 2 = 4

Result: Return 4
```

**Why this works:**
- `4 ^ 1 ^ 2 ^ 1 ^ 2`
- `= 4 ^ (1 ^ 1) ^ (2 ^ 2)`
- `= 4 ^ 0 ^ 0`
- `= 4 ^ 0`
- `= 4`

> **Note:** The XOR operation is perfect for this problem because it has the property that `a ^ a = 0` and `a ^ 0 = a`. This means that when you XOR all numbers, pairs of identical numbers will cancel out to 0, leaving only the single number.

**Time Complexity:** O(n) - you visit each element exactly once
**Space Complexity:** O(1) - you only use a constant amount of extra space
4 changes: 2 additions & 2 deletions explanations/14/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Write a function to find the longest common prefix string amongst an array of st
If there is no common prefix, return an empty string `""`.

**Examples**
```text
```tex
Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Expand All @@ -21,7 +21,7 @@ Explanation: There is no common prefix among the input strings.
```

**Constraints:**
```text
```tex
1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lowercase English letters if it is non-empty.
Expand Down
4 changes: 2 additions & 2 deletions explanations/1431/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Note that multiple kids can have the greatest number of candies.

**Examples**

```text
```tex
Input: candies = [2,3,5,1,3], extraCandies = 3
Output: [true,true,true,false,true]
Explanation: If you give all extraCandies to:
Expand All @@ -30,7 +30,7 @@ Output: [true,false,true]

**Constraints**

```text
```tex
- n == candies.length
- 2 <= n <= 100
- 1 <= candies[i] <= 100
Expand Down
2 changes: 1 addition & 1 deletion explanations/1456/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Explanation: "lee", "eet" and "ode" contain 2 vowels.
```

**Constraints**
```text
```tex
- 1 <= s.length <= 10^5
- s consists of lowercase English letters.
- 1 <= k <= s.length
Expand Down
4 changes: 2 additions & 2 deletions explanations/151/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Note that `s` may contain leading or trailing spaces or multiple spaces between

**Examples**

```text
```tex
Input: s = "the sky is blue"
Output: "blue is sky the"

Expand All @@ -27,7 +27,7 @@ Explanation: You need to reduce multiple spaces between two words to a single sp
```

**Constraints**
```text
```tex
1 <= s.length <= 10^4
s contains English letters (upper-case and lower-case), digits, and spaces ' '.
There is at least one word in s.
Expand Down
4 changes: 2 additions & 2 deletions explanations/169/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The majority element is the element that appears more than `n / 2` times.
You may assume that the majority element always exists in the array.

**Examples**
```text
```tex
Example 1:
Input: nums = [3,2,3]
Output: 3
Expand All @@ -19,7 +19,7 @@ Output: 2
```

**Constraints:**
```text
```tex
n == nums.length
1 <= n <= 5 * 10^4
-10^9 <= nums[i] <= 10^9
Expand Down
4 changes: 2 additions & 2 deletions explanations/1768/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You are given two strings, word1 and word2. Merge the strings by adding letters
Return the merged string.

**Examples**
```text
```tex
Input: word1 = "abc", word2 = "pqr"
Output: "apbqcr"
Explanation: The merged string will be merged as so:
Expand All @@ -32,7 +32,7 @@ merged: a p b q c d
```

**Constraints**
```text
```tex
- 1 <= word1.length, word2.length <= 100
- word1 and word2 consist of lowercase English letters.
```
Expand Down
4 changes: 2 additions & 2 deletions explanations/1957/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Return the final string after the deletion. It can be shown that the answer will

**Examples**

```text
```tex
Input: s = "leeetcode"
Output: "leetcode"
Explanation: Remove an 'e' from the first group of 'e's to create "leetcode". No three consecutive characters are equal, so return "leetcode".
Expand All @@ -29,7 +29,7 @@ Explanation: No three consecutive characters are equal, so return "aab".

**Constraints**

```text
```tex
1 <= s.length <= 10^5
s consists only of lowercase English letters.
```
Expand Down
4 changes: 2 additions & 2 deletions explanations/1991/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ https://leetcode.com/problems/find-the-middle-index-in-array
Given a 0-indexed integer array nums, find the leftmost middleIndex such that the sum of the numbers to the left of middleIndex is equal to the sum of the numbers to the right of middleIndex. Return -1 if no such index exists.

**Examples**
```text
```tex
Input: nums = [2,3,-1,8,4]
Output: 3
Explanation: The sum of the numbers to the left of index 3 is 4 (2+3-1), and to the right is also 4 (4).
Expand All @@ -21,7 +21,7 @@ Explanation: There is no valid middleIndex.
```

**Constraints**
```text
```tex
- 1 <= nums.length <= 100
- -1000 <= nums[i] <= 1000
```
Expand Down
Loading