Update note generation script to auto-detect exercises and improve title formatting
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# LeetCode Notes Generator
|
# 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"
|
NOTES_DIR="src/notes"
|
||||||
EXERCISES_DIR="src/exercises"
|
EXERCISES_DIR="src/exercises"
|
||||||
@@ -9,7 +9,7 @@ EXERCISES_DIR="src/exercises"
|
|||||||
# Create notes directory if it doesn't exist
|
# Create notes directory if it doesn't exist
|
||||||
mkdir -p "$NOTES_DIR"
|
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
|
# Function to convert problem number to 3-digit format
|
||||||
format_problem_number() {
|
format_problem_number() {
|
||||||
@@ -22,6 +22,41 @@ title_to_filename() {
|
|||||||
echo "$1" | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]//g'
|
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
|
# Function to create note file
|
||||||
create_note_file() {
|
create_note_file() {
|
||||||
local problem_num=$1
|
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 "*Note: This is a work in progress. I'll add more details as I reflect on this problem.*" >> "$filename"
|
||||||
|
|
||||||
echo "✅ Created: $filename"
|
echo "✅ Created: $filename"
|
||||||
|
return 0
|
||||||
else
|
else
|
||||||
echo "⏭️ Skipped: $filename (already exists)"
|
echo "⏭️ Skipped: $filename (already exists)"
|
||||||
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Define all solved problems with their details
|
# Counter for statistics
|
||||||
declare -A problems=(
|
created_count=0
|
||||||
["1"]="Two Sum:Easy"
|
skipped_count=0
|
||||||
["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"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create note files for all problems
|
# Scan exercises directory for Python files
|
||||||
for problem_num in "${!problems[@]}"; do
|
if [ -d "$EXERCISES_DIR" ]; then
|
||||||
IFS=':' read -r title difficulty <<< "${problems[$problem_num]}"
|
for file in "$EXERCISES_DIR"/*.py; do
|
||||||
create_note_file "$problem_num" "$title" "$difficulty"
|
if [ -f "$file" ]; then
|
||||||
done
|
# 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 ""
|
||||||
echo "🎉 Note generation complete!"
|
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 "📁 Notes directory: $NOTES_DIR"
|
||||||
echo ""
|
echo ""
|
||||||
echo "💡 Tip: Run this script whenever you solve new problems to automatically create note templates."
|
echo "💡 Tip: Run this script whenever you solve new problems to automatically create note templates."
|
||||||
22
src/notes/167_two_sum_ii_input_array_is_sorted.md
Normal file
22
src/notes/167_two_sum_ii_input_array_is_sorted.md
Normal 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.*
|
||||||
Reference in New Issue
Block a user