Imported from simonesiega/leetcode-solutions (
AGENTS.md). Install upstream withnpx skills add simonesiega/leetcode-solutions. Copyright stays with the author.
Repository instructions for coding agents
Purpose
This repository records Python solutions completed while following the NeetCode All roadmap and while preparing independently for company online assessments and interviews. Keep solutions readable, easy to explain, compatible with Python 3, and free of external dependencies. Correctness, clear complexity analysis, accurate progress metadata, and focused commits matter more than clever abstractions.
Read CONTRIBUTING.md before making changes. Preserve the user's solution and approach unless correctness or an explicit request requires an edit. Never add confidential assessment content, recruiter messages, or private interview information.
Repository structure and sources of truth
neetcode-all/<topic-slug>/<problem-number>.py: NeetCode All roadmap solutions.data/roadmap.json: source of truth for roadmap topics, dated totals snapshot, problem metadata, personal difficulty, status, solve date, and complexity.SOLUTIONS.md: generated roadmap catalog; do not edit it directly.README.md: manual prose plus generated roadmap and company summary blocks.companies/<company>/company.json: source of truth for personal company practice selected for tracking.- The external company candidate list is a separate, pinned source layer; never copy its complete dataset into a manifest.
companies/<company>/README.mdandcompanies/README.md: generated byscripts/company-tracker.js; do not edit them directly.scripts/company-tracker.js: thin company CLI orchestration.scripts/lib/company.js: company state, validation, workspace rules, and Markdown generation.scripts/lib/company-source.js: external source caching, normalization, ranking, filtering, and selection.scripts/lib/csv.js: dependency-free CSV parsing.scripts/roadmap-tracker.js: roadmap lifecycle CLI for registering, starting, solving, validating, and regenerating roadmap problems.scripts/automation.test.js: automation test suite for the automation layer.scripts/lib/cli.js: shared CLI parsing and error handling.scripts/lib/generated-files.js: generated-file drift detection and writes.scripts/lib/json.js: JSON reads and formatting.scripts/lib/markdown.js: Markdown generation and escaping.scripts/lib/paths.js: canonical repository paths.scripts/lib/progress.js: progress aggregation.scripts/lib/roadmap.js: roadmap validation and generation.scripts/lib/solutions.js: solution scaffolds and solution-file checks.scripts/lib/validation.js: shared metadata validation..github/workflows/ci.yml: CI definition.
Keep CLI entry points focused on orchestration. Put reusable behavior in the narrowest existing scripts/lib/ module. Reuse shared rules across roadmap and company flows instead of duplicating logic or adding unnecessary abstractions.
Do not commit cache files, bytecode, editor files, or unrelated changes. Do not overwrite or discard pre-existing user changes.
Workflow 1: add a NeetCode All problem
Use this workflow when asked to add or finish a roadmap problem.
- Inspect
git status, the current diff, nearby solutions,data/roadmap.json,README.md, andSOLUTIONS.md. Confirm that the problem is not already cataloged. - Identify the numeric LeetCode ID, exact title, canonical URL, difficulty, and correct registered topic slug. Ask instead of guessing when the topic or metadata is uncertain.
- If the problem is untracked, register it with
node scripts/roadmap-tracker.js add <id> "<title>" <topic-slug> <Easy|Medium|Hard> --url <canonical-url> [--personal-difficulty 1-10]. Never infer a personal rating. - If the problem is planned, run
node scripts/roadmap-tracker.js start <id>. If the user already created the target solution, preserve it: move it temporarily if needed, runaddandstart, then restore it. Never let the scaffold replace user work. Skip this command when the manifest already saysin-progress. - Finish the accepted solution at the tracked path, preserve the LeetCode method signature and local Python style, and remove
TODO(roadmap-solution)if the scaffold contains it. - Run
node scripts/roadmap-tracker.js solve <id> --time "O(...)" --space "O(...)" [--personal-difficulty 1-10]. The first solve records the current UTC instant insolvedAt; another solve is rejected. Never invent or casually replace that timestamp. Define every complexity symbol such asn,k, ora, and distinguish auxiliary space from returned output when useful. - Do not manually edit
SOLUTIONS.mdor generated README marker blocks. Confirm the CLI regenerated the catalog, solved badge, counts, charts, and topic table. - Review links, ordering, counts, filename, final newline, whitespace, and the complete diff. Test representative normal and boundary cases when possible.
- Run the full validation suite under Required pre-commit review.
- When asked to commit, use the commit skill and the exact subject
solve leetcode #<id>.
Workflow 2: add a company problem
Use this workflow for company-specific preparation, whether the workspace already exists or must be created first.
-
Inspect the working tree. If the workspace exists, read its
company.jsonand generated README; otherwise create it withadd-companyusing only confirmed metadata. Confirm the problem is not already registered. -
Collect the ID, exact title, URL, platform difficulty, optional 1–10 personal difficulty, time complexity, space complexity, and optional notes. Use
nullwhen the personal difficulty is unrated; never infer it. Notes must define complexity variables where needed, for examplek = number of distinct characters. -
For a source-backed problem, use
source-sync,next, andadd-from-sourceso canonical URL, source rank, and frequency come from the pinned CSV. For a manual or OA-specific problem, useadd-problem. For planned problems usestart; for in-progress problems continue with the existing file. Run tracker commands from the repository root and do not manually synchronize generated README files:node scripts/company-tracker.js source-sync <company-slug> node scripts/company-tracker.js next <company-slug> node scripts/company-tracker.js add-from-source <company-slug> <source-key> [--id problem-id] node scripts/company-tracker.js add-problem <company-slug> <id> "<title>" <Easy|Medium|Hard> [--url URL] node scripts/company-tracker.js start <company-slug> <id> node scripts/company-tracker.js solve <company-slug> <id> --time "O(...)" --space "O(...)" [--personal-difficulty 1-10] [--notes TEXT] -
If the user already created
companies/<company>/solutions/<id>.py, preserve it. Temporarily move it outside the solution path if necessary, runadd-problemandstart, then restore the original solution beforesolve. Never let the generated template replace user work. -
Preserve source repository, commit, snapshot date, window, and path. Do not silently refresh the external source. Source-backed ordering follows
sourceRank; manual and custom OA entries remain supported. -
Confirm that the tracker updated
company.json, the company dashboard,companies/README.md, and the company summary inREADME.md. -
Review the implementation, metadata, generated files, and complete diff, then run the full validation suite.
-
When asked to commit, use the exact subject
solve leetcode #<id> @ <company-slug>, preserving the folder slug's spelling and case.
When a requested company workspace does not exist, run node scripts/company-tracker.js add-company "Company Name" first. Add --focus, --slug, or --website only from known information.
Workflow 3: update documentation
- Determine whether the target is manual or generated documentation.
- For roadmap metadata or statistics, update
data/roadmap.json, then runnode scripts/roadmap-tracker.js; the shared roadmap automation ownsSOLUTIONS.mdand the generated README roadmap blocks. Update roadmapsnapshotDateonly when NeetCode totals were actually verified, and backfillsolvedAtonly from reliable repository history. - For company progress, update the manifest through tracker commands, then run
node scripts/company-tracker.js. Company sourcesnapshotDateis separate from roadmapsnapshotDate. Preserve pinned provenance and never hand-edit generated company dashboards. - For prose-only changes, preserve links, headings, and marker comments. Match the file's voice: keep
README.mdandCONTRIBUTING.mdfriendly, informal, concise, and naturally first-person where the maintainer is speaking. - Check internal paths, anchors, code examples, progress counts, and whether documentation still matches actual behavior.
- Run documentation checks and the relevant tests. Generate a concise imperative commit subject from the final diff.
Workflow 4: update CI or automation
- Read
.github/workflows/ci.yml,.github/dependabot.yml, and every script or check affected by the proposed change. - Make the smallest compatible change. Preserve least-privilege permissions, bounded timeouts, concurrency cancellation, supported Python versions, and reproducible action references.
- Keep the public CLI behavior in the entry points and reusable behavior in
scripts/lib/. Updatescripts/automation.test.jswhen automation behavior changes rather than creating overlapping test suites without a clear reason. - Ensure local commands, documentation, and CI commands remain aligned. If a check is added to CI, document it in
CONTRIBUTING.mdwhen contributors are expected to run it locally. - Validate JavaScript syntax and tests locally. Review YAML structure, event triggers, permissions, matrix behavior, shell portability, and dependency-update configuration.
- Inspect the final diff for accidental secret exposure or untrusted pull-request execution risks. Generate the commit subject from the final diff.
Workflow 5: review everything / prepare for commit
Treat review as a real quality check, not just a summary of the changes.
- Inspect
git status --short, unstaged changes, staged changes, and every untracked file intended for the commit. - Confirm scope: one coherent change, no caches or editor artifacts, no accidental deletions, and no unrelated user work.
- Review solution correctness, edge cases, method signatures, complexity claims, personal difficulty metadata, status-consistent
solvedAtvalues, both distinct snapshot-date concepts, company source provenance and ordering, links, generated files, and documentation counts. - Run all available checks. Report any command that cannot run; never describe an unavailable check as passed.
- Check whitespace for tracked and untracked files. Before committing, stage only intended paths and run
git diff --cached --checkplusgit diff --cached. - Use
.agents/skill/commit/SKILL.mdwhen the user asks to commit. After committing, show the resulting subject and remaining working-tree status.
Workflow 6: general maintenance, fixes, and refactors
For requests not covered above, first infer the repository subsystem and desired outcome from the request and existing code. Read adjacent files and tests, keep the diff minimal, preserve public behavior unless the request changes it, update all affected documentation, and add or adjust tests when behavior changes. Apply the same review gate as every other workflow. Derive a concise imperative commit subject from the actual diff rather than from an early plan.
Required pre-commit review
Run from the repository root:
for file in scripts/*.js scripts/lib/*.js; do node --check "$file"; done
node scripts/roadmap-tracker.js --check
node scripts/company-tracker.js --check
node --test scripts/automation.test.js
ruff check neetcode-all companies
python -m compileall -q neetcode-all companies
git diff --check
Also run focused tests for changed behavior and inspect untracked files because plain git diff --check does not include them. If Python is unavailable, say so clearly and rely on CI for that check; do not install tools or dependencies without permission.
Commit and Dependabot rules
- Do not commit unless the user explicitly asks.
- Never use
git add .; stage only reviewed paths. - NeetCode roadmap commit:
solve leetcode #<id>. - Company solution commit:
solve leetcode #<id> @ <company-slug>. - Documentation, CI, review fixes, and general maintenance: derive a short imperative subject from the final staged diff.
- Do not append a generated
Merge pull request #...subject to a normal commit. - The GitHub repository is configured as squash-only: merge commits and rebase merges are disabled, squash merging is enabled, merged branches are deleted, and a one-commit PR keeps its commit title. Preserve these repository settings.
- For a Dependabot PR requested as a squash merge, create exactly one squash commit containing the dependency update. Use the Dependabot commit/PR subject, not an additional local commit and not a merge commit. Follow the dedicated instructions in
.agents/skill/commit/SKILL.md.