Skip to main content

A tool to organize and generate LeetCode problems and solutions.

Project description

leetcrate

A CLI tool that fetches LeetCode problems via the GraphQL API and generates language-specific boilerplate solution files with runnable test harnesses.


Table of Contents


Overview

  • Fetch problem metadata via LeetCode's GraphQL API
  • Generate boilerplate solutions in five languages: Python, JavaScript, Go, Java, and C++
  • Populate runnable test harnesses for every supported language
  • Organize output inside problems/ under completed/ and incomplete/
  • Optional workspace folders for contests, courses, and interview prep

Prerequisites

  • Python 3.10+ on your PATH
  • requests package (installed automatically with the package)

Installation

From source (editable install)

git clone https://github.com/Borgerod/leetcrate.git
cd leetcrate
pip install -e .

Verify

leetcrate --version

Configuration

Run leetcrate init in your workspace directory to create a settings.INI:

[LeetCode Problem Generator]
language = python

[Framework]
contests = false
courses  = false
interview = false

Accepted language values (case-insensitive):

Value File extension
python .py
javascript / js .js
go .go
java .java
c++ / cpp .cpp

The file is re-read on every run — no restart needed after a language change.


Usage

init

First-time setup. Creates the workspace framework and settings.INI.

leetcrate init

You will be prompted to choose a full framework or a minimal install, and optionally enable the contests, courses, and interview folders.


generate

Fetch a problem and write template files.

leetcrate generate two-sum
# or pass the full URL:
leetcrate generate https://leetcode.com/problems/two-sum/
# omit the slug to be prompted interactively:
leetcrate generate

What happens:

  1. Fetches problem data (title, difficulty, description, tags)
  2. Downloads the official code snippet for your configured language
  3. Parses function signatures and example test cases
  4. Creates problems/incomplete/<id>_<Title>/
  5. Writes a language-specific file with a stub solution and a working test harness

If the folder already exists the script updates it without overwriting any solution you have already written. Move a finished solution into problems/completed/ to track progress.


update

Add any optional folders that are enabled in settings.INI but not yet present on disk.

leetcrate update

Folder Structure

Running leetcrate init with all optional folders enabled creates:

./_your_workspace_/
    ├── settings.INI
    ├── problems/
    │   ├── completed/
    │   └── incomplete/
[OPTIONAL]
    ├── contests/
    │   ├── bi_weekly/
    │   └── weekly/
    ├── courses/
    └── interview/
        ├── mock_assessment/
        └── online_interview/
            └── [Name of workplace]/

A generated problem folder looks like:

problems/
    incomplete/
        1_Two_Sum/
            description.txt      # Cleaned plain-text problem statement
            two_sum.py           # Boilerplate stub + runnable test harness

Generated File Format

Each solution file contains:

  • The official function/class stub from LeetCode
  • A test harness that exercises every example case from the problem statement
  • A git commit message template at the bottom (for copy-paste convenience)

Language Notes

Language Test runner style
Python if __name__ == "__main__" with a for loop over cases
JavaScript console.log for each case
Go main() with typed slice literals and fmt.Println
Java Object[][] cases, casted to parameter types, printed with Arrays.toString
C++ std::vector<std::pair<...>> cases, printed via helper loops

Linked-list problems automatically inject the ListNode class and a build_linked_list helper into the generated file.


Dev Tools

Both scripts live in tests/ and are intended for local development only.

tests/generator_test.py

Bulk-generates a hardcoded list of problems using leetcrate generate. Edit the slugs list inside the file to change which problems are scaffolded.

python tests/generator_test.py

tests/run_test.py

Discovers every problem folder under problems/ and runs the solution file that matches the language in settings.INI.

python tests/run_test.py

Runtime requirements per language:

Language Required on PATH
python python
javascript node
go go
java javac + java
cpp / c++ g++

Troubleshooting

Issue Fix
No settings.INI found Run leetcrate init first
Warning: Could not read settings.INI Ensure the file is UTF-8 encoded and contains a valid language = value line
Locked problem fetch fails Log in to LeetCode in a browser first, or avoid locked problems
Wrong types in test harness Check your language value in settings.INI matches the file you want to run
Need to re-generate after language change Delete the folder and run leetcrate generate <slug> again

TODO:

  • Make generator for extra testcases

    • Fix broken testcase generator
  • Make generator for git push description.

  • crate tests/run_test.py - will run the 4 generates files (according to set language in settings.ini) (NOTE: this is a dev tool).

    • install c++, java, javascript and go in /.venv, so dev can run the codes locally and not rely on online compilers while building.
  • crate tests/generator_test.py - will generates cases for set language (settings.ini) for the leetcode projects set in generator_test (NOTE: this is a dev tool).

  • Update v0.2.0 - descr:
    add clause for handling nodes, add Adjusted test runner(iterates over (vals, pos) pairs for linked list problems), dynamic type notations, add dynamic comments.

    • Update script: Python
    • Update script: C++
    • Update script: Java
    • Update script: JavaScript
    • Update script: Go
  • Add docs to python components

  • Turn project into package

    • Add package directory structure (src/ if needed)
    • Ensure all modules have init.py
    • Update pyproject.toml with metadata
    • Specify dependencies in pyproject.toml
    • Add classifiers and license info
    • Add README.md with usage
    • Add LICENSE file
    • Add MANIFEST.in if needed
    • Test local install (pip install -e .)
    • Verify import/usage from clean env

    [OPTIONAL]

    • (Optional) Add setup.cfg/setup.py
    • (Optional) Add tests/ directory
    • (Optional) Set up CI
    • (Optional) Publish to PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leetcrate-1.0.0.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leetcrate-1.0.0-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

Details for the file leetcrate-1.0.0.tar.gz.

File metadata

  • Download URL: leetcrate-1.0.0.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for leetcrate-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5381e4d25254476a4fa7d428268cd07d1066c49ef5e10c2a7fa98e7c736f5e3b
MD5 b5e1abe0bc1e7a0e58078009147e2471
BLAKE2b-256 e7084300c2fa8a3cdf5d2138983cae461a186304bc9c9c30e59f7f5efa9c08c1

See more details on using hashes here.

File details

Details for the file leetcrate-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: leetcrate-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 31.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for leetcrate-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fde644b24a0ad7ff803af2fdd28c25c05f9dbd501ab1ecfc3f1484f20b30eecc
MD5 9eb4a2a7dca0c2dbfd047f7e41094d32
BLAKE2b-256 fb55e0cc05f21810c7105b74542d0d65587f620fbb6e0654de52727dcf5bd156

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page