Skip to content

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

LeetCode in Rust

A local workspace for solving LeetCode problems in Rust with full IDE support (rust-analyzer), solution archiving, and progress tracking. Built for 42 school students learning Rust from C.


Requirements

Install the Rust toolchain if you don't have it:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Recommended: cargo-watch for live test feedback — cargo install cargo-watch

Install

git clone https://github.com/ihibti/leetcode-rust.git
cd leetcode-rust

Solve a Problem

# Draw a random unsolved problem from Amazon's last-30-days interview list
cargo next

# ...or fetch a specific problem — generates the impl skeleton and test cases
cargo solve https://leetcode.com/problems/two-sum/

# Open src/solution.rs and fill in your solution
# Tests auto-rerun on save with cargo-watch
cargo watch -x test

# When you're done, save it to your archive
# Name, difficulty and tags are auto-filled from LeetCode
cargo archive

# You can still override with flags if needed
cargo archive my-two-sum -r "HashMap,entry-api"   # custom file name, Rust concepts practiced

# See your stats
cargo progress

Commands

Command Description
cargo next [30d|3m|6m|6m+|all] Draw a frequency-weighted random unsolved problem from a company list (default: Amazon, 30d)
cargo next -c Google -d medium Pick the company (case-sensitive folder name) and restrict difficulty
cargo solve <url> Fetch problem from LeetCode, generate impl skeleton and tests
cargo solve Start with a blank template (no URL)
cargo solve --force Overwrite solution.rs without confirmation
cargo archive [name] Save current solution (name, difficulty and tags auto-filled from LeetCode, optional: -r rust concepts)
cargo progress Show solving stats and progress
cargo watch -x test Auto-run tests on file changes

Workflow

cargo next / cargo solve <url> → edit solution.rs → cargo watch -x test → cargo archive
             ↑                                                                  |
             └──────────────────────────────────────────────────────────────────┘

When you run cargo solve <url>, it fetches the problem from LeetCode, generates the impl Solution skeleton and test cases from the examples. Open src/solution.rs — the method signature and tests are ready, just fill in the implementation.

cargo next does the same, but picks the problem for you: it downloads a company's interview list from liquidslr/leetcode-company-wise-problems, drops everything already in archive/, and draws at random, weighted by how often the problem was reported. Premium-only problems and problems without a Rust template are skipped automatically. The window (30d, 3m, 6m, 6m+, all) is relative to that repo's latest snapshot, not to today.

When you archive, the problem name, difficulty and tags are pulled from the session, and the problem's slug is recorded in the file header. That header is what cargo next uses to know what you've already solved — to start a fresh grind, empty archive/.

rust-analyzer Setup

rust-analyzer gives you completions, docs on hover, inline type hints, and compiler errors in your editor. You need to install it for your editor.

VS Code:

  1. Install the rust-analyzer extension
  2. Open VS Code at the repo root (code . from leetcode-rust/) — rust-analyzer needs to find Cargo.toml at the top level to work correctly
  3. It activates automatically once the workspace is open

Neovim:

  1. Install rust-analyzer: rustup component add rust-analyzer
  2. Your LSP config should pick it up (if using nvim-lspconfig, it works out of the box)
  3. Open Neovim from the repo root so it finds Cargo.toml

Project Structure

leetcode-rust/
├── src/
│   ├── lib.rs           # Crate root
│   ├── solution.rs      # YOUR WORKING FILE
│   ├── types.rs         # ListNode, TreeNode
│   └── macros.rs        # list![], tree![] test helpers
├── xtask/               # CLI tooling (solve, archive, progress)
├── archive/             # Your solved problems
└── docs/
    ├── fundamentals.md  # Rust syntax quick reference (for C programmers)
    ├── cheatsheet.md    # C-to-Rust patterns in depth
    ├── resources.md     # Learning resources + neetcode roadmap
    └── ai-tutor.md      # Setting up AI assistance

Documentation

  • Fundamentals — "What does :: mean?" Quick answers to Rust syntax that surprises C programmers
  • Cheatsheet — Side-by-side C and Rust patterns for LeetCode
  • Resources — Curated learning resources + neetcode problem roadmap
  • AI Tutor — Set up Claude Code or other AI tools as your Rust tutor

Credits

Shoutout to Idrissa for getting me into Rust.

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages