Skip to content

Commit f7d88d7

Browse files
committed
Fix: Exclude premium problems from All and All-TODO sets, fix problem 27 solution format
1 parent 9d945bf commit f7d88d7

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

scripts/normalize_book_sets.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,39 +118,53 @@ def normalize_book_sets(
118118
print("Error: The root of the JSON file must be an array.")
119119
return
120120

121-
# Find the "All-TODO" and "All" objects
121+
# Find the "All-TODO", "All" objects, and get premium list
122122
all_todo_obj = None
123123
all_obj = None
124+
premium_set = set()
124125

125126
for obj in data:
126127
if obj.get("title") == "All-TODO":
127128
all_todo_obj = obj
128129
elif obj.get("title") == "All":
129130
all_obj = obj
131+
elif "premium" in obj:
132+
# Get premium problems list
133+
premium_set = set(obj.get("premium", []))
130134

131135
changes_made = False
132136

133-
# Process "All-TODO": Remove problems that have both solution and explanation
137+
# Process "All-TODO": Remove problems that have both solution and explanation or are premium
134138
if all_todo_obj:
135139
original_count = len(all_todo_obj.get("problems", []))
136140
problems = all_todo_obj.get("problems", [])
137141
removed = []
142+
removed_premium = []
138143

139144
new_problems = []
140145
for problem_num in problems:
141-
if has_both_solution_and_explanation(
146+
# Remove if premium
147+
if problem_num in premium_set:
148+
removed_premium.append(problem_num)
149+
# Remove if has both solution and explanation
150+
elif has_both_solution_and_explanation(
142151
problem_num, solutions_path, explanations_path
143152
):
144153
removed.append(problem_num)
145154
else:
146155
new_problems.append(problem_num)
147156

148-
if removed:
157+
if removed or removed_premium:
149158
changes_made = True
150-
print(
151-
f"\n[All-TODO] Removing {len(removed)} problems with both solution and explanation:"
152-
)
153-
print(f" Removed: {removed[:10]}{'...' if len(removed) > 10 else ''}")
159+
print(f"\n[All-TODO] Removing problems:")
160+
if removed_premium:
161+
print(
162+
f" Removed {len(removed_premium)} premium problems: {removed_premium[:10]}{'...' if len(removed_premium) > 10 else ''}"
163+
)
164+
if removed:
165+
print(
166+
f" Removed {len(removed)} problems with both solution and explanation: {removed[:10]}{'...' if len(removed) > 10 else ''}"
167+
)
154168
all_todo_obj["problems"] = sorted(new_problems)
155169
print(f" Updated count: {original_count} -> {len(new_problems)}")
156170
else:
@@ -170,7 +184,7 @@ def normalize_book_sets(
170184
if d.is_dir() and d.name.isdigit() and not d.name.startswith("todo-")
171185
}
172186

173-
# Find problems that have both
187+
# Find problems that have both (excluding premium problems)
174188
problems_with_both = sorted(
175189
[
176190
p
@@ -179,6 +193,7 @@ def normalize_book_sets(
179193
and has_both_solution_and_explanation(
180194
p, solutions_path, explanations_path
181195
)
196+
and p not in premium_set # Exclude premium problems
182197
]
183198
)
184199

solutions/27/01.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
from typing import List
22

33

4-
def removeElement(nums: List[int], val: int) -> int:
5-
slow = 0
6-
7-
# Iterate through the array with fast pointer
8-
for fast in range(len(nums)):
9-
# If current element is not equal to val, keep it
10-
if nums[fast] != val:
11-
nums[slow] = nums[fast]
12-
slow += 1
13-
14-
return slow
4+
class Solution:
5+
def removeElement(self, nums: List[int], val: int) -> int:
6+
slow = 0
7+
8+
# Iterate through the array with fast pointer
9+
for fast in range(len(nums)):
10+
# If current element is not equal to val, keep it
11+
if nums[fast] != val:
12+
nums[slow] = nums[fast]
13+
slow += 1
14+
15+
return slow

0 commit comments

Comments
 (0)