This repository contains my LeetCode solutions along with a management system that:
- Automatically syncs solutions from LeetCode
- Organizes problems into structured directories
- Maintains a PostgreSQL database of problems and solutions
- Provides a REST API to query solutions (Using Postgrest)
.
├── problems/ # Organized LeetCode solutions
│ ├── 0/ # Problems without LeetCode IDs
│ ├── 1-100/ # Problems 1-100
│ ├── 101-200/ # Problems 101-200
│ └── ... # More problem groups
├── leetcode-db/ # Database and API management
│ ├── cmd/
│ │ └── populate-db/ # Problem organization scripts
│ ├── internal/ # Internal packages
│ └── scripts/ # Database initialization
└── .github/workflows/ # GitHub Actions workflows
- Weekly automatic sync with LeetCode (every Saturday at 8:00 UTC)
- Manual sync available through GitHub Actions
- Uses leetcode-sync
- Problems are grouped by hundreds (1-100, 101-200, etc.)
- Special '0' directory for problems without LeetCode IDs
- Consistent naming format:
{id}-{problem_name}
- Stores problem metadata and solutions
- Tracks multiple solutions per problem
- Maintains solution history with commit dates
- Full-text search for problem titles
- Language statistics
Available endpoints:
/recent_solutions: Get recently updated solutions/problem_solutions: Get all solutions with problem details/problem_summary: Get problem statistics/language_stats: Get programming language statistics/rpc/search_problems: Search problems by title (function endpoint)
-
Clone the Repo
git clone https://github.com/nathannaveen/leetcode-submissions.git cd leetcode-submissions -
Database Setup
cd leetcode-db docker-compose up -d -
Populate Database
go run cmd/main.go
- Syncs solutions from LeetCode
- Requires LeetCode session tokens (set in repository secrets)
- Runs weekly or manually
Triggered after successful sync:
- Organizes problems into directories
- Renames problems in the '0' directory
- Updates the database
-
Get Recent Solutions
GET http://localhost:3000/recent_solutions?limit=10 -
Search Problems
GET http://localhost:3000/rpc/search_problems?search_query=two%20sumResponse:
[ { "id": 1, "title": "Two Sum", "description": "Given an array of integers...", "relevance": 0.8 } ] -
Get Language Statistics
GET http://localhost:3000/language_statsResponse:
[ { "language": "go", "solution_count": 150, "problem_ids": [1, 2, 3, ...] } ] -
Get Problem Solutions
GET http://localhost:3000/problem_solutions?problem_id=eq.1Response:
[ { "id": 1, "title": "Two Sum", "language": "java", "code": "...", "commit_date": "..." } ] -
Get Problem Summary
GET http://localhost:3000/problem_summary?order=solved_at.descResponse:
[ { "id": 1, "title": "Two Sum", "solution_count": 2, "languages": ["go", "java"] } ]
Note: All endpoints support PostgREST's filtering, ordering, and pagination:
?limit=10: Limit results?order=column.desc: Order results?column=eq.value: Exact match?column=like.*pattern*: Pattern match?select=column1,column2: Select specific columns