Status: Informational
Scope: Creating solution skeleton files insolutions/viascripts/new_problem.bat/scripts/new_problem.sh
Last Updated: {{ git_revision_date_localized }}
Created: {{ git_creation_date_localized }}
scripts/new_problem.bat / scripts/new_problem.sh are thin wrappers around CodeGen:
- They run
python -m codegen new ... - They forward all arguments as-is
- They return the same exit code as CodeGen
Use this when you want to create a new reference solution skeleton for a LeetCode problem:
- Output directory:
solutions/ - Output filename format:
<id:04d>_<slug>.py(example:0001_two_sum.py)
If the solution file already exists, CodeGen will refuse to overwrite (unless you delete it and regenerate).
Run from the repository root.
.\scripts\new_problem.bat <problem_id> [options]./scripts/new_problem.sh <problem_id> [options]python -m codegen new <problem_id> [options]problem_id(int): LeetCode problem number (frontend id), e.g.1
--with-tests: Generate.in/.outtest files from LeetCode examples (undertests/).--force: Overwrite existing test files (only applies with--with-tests).--dry-run: Print generated content to stdout and do not write files.--solve-mode {placeholder,infer,tiered}:placeholder: TODO-stylesolve()infer: auto-generatesolve()based on inferred I/O schematiered: config-based Tier-1 / Tier-1.5solve()generation (codec-based)
--codec-mode {import,inline}: Override codec emission strategy for tiered solve generation (default: fromconfig/problem-support.yaml)--header-level {minimal,standard,full}: Controls the amount of problem header content (default:full)
Even if you do not pass --solve-mode tiered, CodeGen will auto-use tiered solve generation when the problem is marked as Tier "1" or "1.5" in:
config/problem-support.yaml
This is what enables correct handling for structures like ListNode / TreeNode / cycles via the codec layer.
Tiered generation supports two codec emission strategies:
- import:
solve()imports codec utilities fromrunner.utils.codec - inline: codec utilities are embedded into the generated solution file
Default behavior is controlled by problem config (codec_mode in config/problem-support.yaml).
You can override it for a single run via --codec-mode.
Generate a new solution skeleton:
.\scripts\new_problem.bat 1Generate solution skeleton + LeetCode example tests:
.\scripts\new_problem.bat 1 --with-testsGenerate with auto-inferred solve():
.\scripts\new_problem.bat 1 --solve-mode inferPreview without writing:
.\scripts\new_problem.bat 1 --with-tests --dry-run