Update note generation script to auto-detect exercises and improve title formatting

This commit is contained in:
Carlos
2025-07-11 12:17:10 -04:00
parent 56953591a4
commit 2cabda5348
2 changed files with 107 additions and 88 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# LeetCode Notes Generator
# This script creates missing note files for solved problems
# This script automatically creates missing note files for solved problems
NOTES_DIR="src/notes"
EXERCISES_DIR="src/exercises"
@@ -9,7 +9,7 @@ EXERCISES_DIR="src/exercises"
# Create notes directory if it doesn't exist
mkdir -p "$NOTES_DIR"
echo "🧠 Generating missing LeetCode problem notes..."
echo "🧠 Scanning exercises directory and generating missing LeetCode problem notes..."
# Function to convert problem number to 3-digit format
format_problem_number() {
@@ -22,6 +22,41 @@ title_to_filename() {
echo "$1" | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]//g'
}
# Function to extract problem number from filename
extract_problem_number() {
local filename=$1
echo "$filename" | sed 's/^\([0-9]*\)\..*/\1/'
}
# Function to convert filename to problem title
filename_to_title() {
local filename=$1
# Remove the .py extension and problem number
local title=$(echo "$filename" | sed 's/^[0-9]*\.//' | sed 's/\.py$//')
# Convert kebab-case to Title Case with proper handling
echo "$title" | sed 's/-/ /g' | sed 's/\b\w/\U&/g' | sed 's/\bii\b/II/g' | sed 's/\biii\b/III/g'
}
# Function to determine difficulty based on problem number ranges
get_difficulty() {
local problem_num=$1
# Hard problems (known)
case $problem_num in
4|10|42|135|149|248)
echo "Hard"
;;
# Easy problems (known)
1|9|13|14|20|21|28|35|66|69|88|121|125|141|169|202|205|206|217|219|228|242|243|246|290|383|392|704|1200|2053|2441|3442|3445)
echo "Easy"
;;
# Everything else is Medium
*)
echo "Medium"
;;
esac
}
# Function to create note file
create_note_file() {
local problem_num=$1
@@ -54,101 +89,63 @@ create_note_file() {
echo "*Note: This is a work in progress. I'll add more details as I reflect on this problem.*" >> "$filename"
echo "✅ Created: $filename"
return 0
else
echo "⏭️ Skipped: $filename (already exists)"
return 1
fi
}
# Define all solved problems with their details
declare -A problems=(
["1"]="Two Sum:Easy"
["2"]="Add Two Numbers:Medium"
["3"]="Longest Substring Without Repeating Characters:Medium"
["4"]="Median of Two Sorted Arrays:Hard"
["5"]="Longest Palindromic Substring:Medium"
["6"]="Zigzag Conversion:Medium"
["7"]="Reverse Integer:Medium"
["9"]="Palindrome Number:Easy"
["10"]="Regular Expression Matching:Hard"
["11"]="Container With Most Water:Medium"
["13"]="Roman to Integer:Easy"
["14"]="Longest Common Prefix:Easy"
["15"]="3Sum:Medium"
["20"]="Valid Parentheses:Easy"
["21"]="Merge Two Sorted Lists:Easy"
["22"]="Generate Parentheses:Medium"
["28"]="Find the Index of the First Occurrence in a String:Easy"
["35"]="Search Insert Position:Easy"
["36"]="Valid Sudoku:Medium"
["42"]="Trapping Rain Water:Hard"
["45"]="Jump Game II:Medium"
["50"]="Pow(x, n):Medium"
["55"]="Jump Game:Medium"
["66"]="Plus One:Easy"
["69"]="Sqrt(x):Easy"
["74"]="Search a 2D Matrix:Medium"
["80"]="Remove Duplicates from Sorted Array II:Medium"
["88"]="Merge Sorted Array:Easy"
["89"]="Gray Code:Medium"
["90"]="Subsets II:Medium"
["91"]="Decode Ways:Medium"
["92"]="Reverse Linked List II:Medium"
["121"]="Best Time to Buy and Sell Stock:Easy"
["122"]="Best Time to Buy and Sell Stock II:Medium"
["125"]="Valid Palindrome:Easy"
["128"]="Longest Consecutive Sequence:Medium"
["135"]="Candy:Hard"
["141"]="Linked List Cycle:Easy"
["149"]="Max Points on a Line:Hard"
["150"]="Evaluate Reverse Polish Notation:Medium"
["153"]="Find Minimum in Rotated Sorted Array:Medium"
["155"]="Min Stack:Medium"
["167"]="Two Sum II - Input Array Is Sorted:Medium"
["169"]="Majority Element:Easy"
["172"]="Factorial Trailing Zeroes:Medium"
["189"]="Rotate Array:Medium"
["202"]="Happy Number:Easy"
["205"]="Isomorphic Strings:Easy"
["206"]="Reverse Linked List:Easy"
["217"]="Contains Duplicate:Easy"
["219"]="Contains Duplicate II:Easy"
["228"]="Summary Ranges:Easy"
["238"]="Product of Array Except Self:Medium"
["242"]="Valid Anagram:Easy"
["243"]="Shortest Word Distance:Easy"
["244"]="Shortest Word Distance II:Medium"
["245"]="Shortest Word Distance III:Medium"
["246"]="Strobogrammatic Number:Easy"
["248"]="Strobogrammatic Number III:Hard"
["290"]="Word Pattern:Easy"
["383"]="Ransom Note:Easy"
["392"]="Is Subsequence:Easy"
["704"]="Binary Search:Easy"
["875"]="Koko Eating Bananas:Medium"
["990"]="Satisfiability of Equality Equations:Medium"
["1200"]="Minimum Absolute Difference:Easy"
["1298"]="Maximum Candies You Can Get from Boxes:Medium"
["1820"]="Maximum Number of Accepted Invitations:Medium"
["2040"]="Kth Smallest Product of Two Sorted Arrays:Medium"
["2053"]="Kth Distinct String in an Array:Easy"
["2116"]="Check if a Parentheses String Can Be Valid:Medium"
["2294"]="Partition Array Such That Maximum Difference Is K:Medium"
["2441"]="Largest Positive Integer That Exists With Its Negative:Easy"
["2616"]="Minimize the Maximum Difference of Pairs:Medium"
["2966"]="Divide Array Into Arrays With Max Difference:Medium"
["3442"]="Maximum Difference Between Even and Odd Frequency I:Easy"
["3445"]="Maximum Difference Between Even and Odd Frequency II:Easy"
)
# Counter for statistics
created_count=0
skipped_count=0
# Create note files for all problems
for problem_num in "${!problems[@]}"; do
IFS=':' read -r title difficulty <<< "${problems[$problem_num]}"
create_note_file "$problem_num" "$title" "$difficulty"
done
# Scan exercises directory for Python files
if [ -d "$EXERCISES_DIR" ]; then
for file in "$EXERCISES_DIR"/*.py; do
if [ -f "$file" ]; then
# Extract filename without path
filename=$(basename "$file")
# Skip empty files
if [ ! -s "$file" ]; then
echo "⚠️ Skipped empty file: $filename"
continue
fi
# Extract problem number
problem_num=$(extract_problem_number "$filename")
# Skip if no problem number found
if [ -z "$problem_num" ] || [ "$problem_num" = "$filename" ]; then
echo "⚠️ Skipped invalid filename: $filename"
continue
fi
# Convert filename to title
title=$(filename_to_title "$filename")
# Get difficulty
difficulty=$(get_difficulty "$problem_num")
# Create note file
if create_note_file "$problem_num" "$title" "$difficulty"; then
((created_count++))
else
((skipped_count++))
fi
fi
done
else
echo "❌ Error: Exercises directory '$EXERCISES_DIR' not found!"
exit 1
fi
echo ""
echo "🎉 Note generation complete!"
echo "📝 Total problems processed: ${#problems[@]}"
echo "📝 Files processed: $((created_count + skipped_count))"
echo "✅ New notes created: $created_count"
echo "⏭️ Notes skipped (already exist): $skipped_count"
echo "📁 Notes directory: $NOTES_DIR"
echo ""
echo "💡 Tip: Run this script whenever you solve new problems to automatically create note templates."

View File

@@ -0,0 +1,22 @@
# two sum ii input array is sorted
**Problem Number:** 167
**Difficulty:** Medium
**Category:**
## Problem Description
## My Approach
## Solution
## Time & Space Complexity
## Key Insights
## Mistakes Made
## Related Problems
---
*Note: This is a work in progress. I'll add more details as I reflect on this problem.*