Create New Problem (new_problem)¶
Status: Informational
Scope: Creating solution skeleton files insolutions/viascripts/new_problem.bat/scripts/new_problem.sh
Last Updated: January 4, 2026 15:11:06
Created: January 3, 2026 21:02:34
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
When to use this¶
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).
Usage¶
Run from the repository root.
Windows¶
Linux / macOS¶
Equivalent direct command (same behavior)¶
Parameters¶
Required¶
problem_id(int): LeetCode problem number (frontend id), e.g.1
Optional flags¶
--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)
Tiered auto-detection (Tier-1 / Tier-1.5)¶
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.
Codec mode (import vs inline)¶
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.
Examples¶
Generate a new solution skeleton:
Generate solution skeleton + LeetCode example tests:
Generate with auto-inferred solve():
Preview without writing: