Skip to content
fuad-daoudPublic

About

Repository to have solutions in python for leetcode or any similar platform

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Solve

LeetCode workbench in Python. Two files you touch: solve.py (the current problem) and cases.txt (its test cases).

Setup

make setup   # once per clone: installs the pre-commit hook

Workflow

make next                                             # first unticked problem in ROADMAP.md → solve.py, cases.txt, problem.md (premium ones get struck through and skipped)
make start P=https://leetcode.com/problems/two-sum/   # …or any problem by URL / slug / number (make start P=53)
make path                                             # …or the next problem on paths/interview.txt (core by day, then stretch; never the mock six)
make test                                             # run every case, LeetCode-style report
make commit                                           # "feat: solved 1. Two Sum [Easy]"; hook saves to problems/ + updates tables

In neovim, <leader>rp from solve.py runs make test into a right-hand column (cases.txt on top, report below); <leader>rd opens the problem statement (problem.md) in a new tab.

A Socratic coach lives under <leader>a (one agent session per problem, never hands over the solution): <leader>ah next hint (4-rung ladder), <leader>aa ask about the selection, <leader>ar review the attempt, <leader>ad debrief once solved (reveals the approach — asks first if tests still fail), <leader>at toggle the pane, <leader>ac terminal chat, <leader>am pick the engine (claude or agy), model and effort — switching engine restarts the current problem's session. Also :Solve, :Solve model, :SolveHint, :SolveAsk, :SolveReview, :SolveDebrief, :SolveChat.

cases.txt

One JSON argument per line, exactly as LeetCode's testcase box shows them. Blank line between cases. => value is the expected output (optional); => ~ value compares lists ignoring order.

[2,7,11,15]
9
=> [0,1]

[3,3]
6

make add appends a case interactively, or just edit the file.

Saving

make commit stages solve.py, cases.txt, problem.md and commits as feat: solved N. Title [Difficulty]. The pre-commit hook fires only when solve.py is staged. It refuses the commit if cases.txt has failures (--no-verify to override), then copies solve.py → problems/NNNN-slug.py, cases.txt → problems/NNNN-slug.cases.txt, regenerates the table below, ticks the problem in ROADMAP.md, and stages all of it. make save does the same by hand.

make start refuses to overwrite solve.py while it holds unsaved work on a different problem (--force via python3 lc.py start --force …).

Discord

Mirrors the forum-post-per-problem routine, in the channel for the problem's difficulty (skipped silently when ~/.config/solve/discord.json doesn't exist; a Discord failure is printed but never fails the command):

  • make start / make next creates the post — title, In Progress tag, the LeetCode URL as the first message — unless a post with that title already exists (yours or a friend's), which is left untouched.
  • the post-commit hook, after a commit that includes solve.py, swaps In Progress / Not Solved for Solved (other tags are kept) and posts the class Solution body in a ```py block (header, imports and harness stripped). No post yet → it is created tagged Solved. Re-committing the same code is a no-op.

One-time setup: create an application at https://discord.com/developers/applications → Bot → copy the token; invite it with View Channels, Send Messages, Send Messages in Threads, Create Public Threads, Read Message History, Manage Threads (needed to apply the Solved tag when it is a mod-only tag) (OAuth2 → URL Generator, scope bot); turn on Developer Mode in Discord's settings and right-click each forum channel → Copy Channel ID. Then:

// ~/.config/solve/discord.json — one forum channel id per difficulty; missing ones are skipped
{ "token": "…", "channels": { "Easy": "123…", "Medium": "456…" } }

Layout

solve.py  cases.txt   working files (+ problem.md, the statement)
lc.py                 the tool (stdlib only); `make check` runs its tests, `make smoke` tries it on live LeetCode
discord.py            posts solutions to Discord (used by .githooks/post-commit)
problems/             saved solutions + their cases
archive/              pre-2026 Codeforces / AtCoder / C++ / Elixir era (see archive/README.md)

Solved

# Problem Difficulty Solution
1 Two Sum Easy 0001-two-sum.py
3 Longest Substring Without Repeating Characters Medium 0003-longest-substring-without-repeating-characters.py
6 Zigzag Conversion Medium 0006-zigzag-conversion.py
11 Container With Most Water Medium 0011-container-with-most-water.py
15 3Sum Medium 0015-3sum.py
20 Valid Parentheses Easy 0020-valid-parentheses.py
22 Generate Parentheses Medium 0022-generate-parentheses.py
26 Remove Duplicates from Sorted Array Easy 0026-remove-duplicates-from-sorted-array.py
36 Valid Sudoku Medium 0036-valid-sudoku.py
42 Trapping Rain Water Hard 0042-trapping-rain-water.py
49 Group Anagrams Medium 0049-group-anagrams.py
53 Maximum Subarray Medium 0053-maximum-subarray.py
66 Plus One Easy 0066-plus-one.py
121 Best Time to Buy and Sell Stock Easy 0121-best-time-to-buy-and-sell-stock.py
122 Best Time to Buy and Sell Stock II Medium 0122-best-time-to-buy-and-sell-stock-ii.py
125 Valid Palindrome Easy 0125-valid-palindrome.py
128 Longest Consecutive Sequence Medium 0128-longest-consecutive-sequence.py
136 Single Number Easy 0136-single-number.py
150 Evaluate Reverse Polish Notation Medium 0150-evaluate-reverse-polish-notation.py
153 Find Minimum in Rotated Sorted Array Medium 0153-find-minimum-in-rotated-sorted-array.py
155 Min Stack Medium 0155-min-stack.py
167 Two Sum II - Input Array Is Sorted Medium 0167-two-sum-ii-input-array-is-sorted.py
189 Rotate Array Medium 0189-rotate-array.py
217 Contains Duplicate Easy 0217-contains-duplicate.py
224 Basic Calculator Hard 0224-basic-calculator.py
238 Product of Array Except Self Medium 0238-product-of-array-except-self.py
242 Valid Anagram Easy 0242-valid-anagram.py
347 Top K Frequent Elements Medium 0347-top-k-frequent-elements.py
350 Intersection of Two Arrays II Easy 0350-intersection-of-two-arrays-ii.py
424 Longest Repeating Character Replacement Medium 0424-longest-repeating-character-replacement.py
567 Permutation in String Medium 0567-permutation-in-string.py
739 Daily Temperatures Medium 0739-daily-temperatures.py
875 Koko Eating Bananas Medium 0875-koko-eating-bananas.py

About

Repository to have solutions in python for leetcode or any similar platform

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages