Generate a LeetCode problem template file
Determine the target folder. If a second argument was provided ($ARGUMENTS[1]), use problems/$ARGUMENTS[1]/. Otherwise, place the file into problems/general/ subdirectory.
Look up the problem. Use your training data to find LeetCode problem number $ARGUMENTS[0]. You need: the title, full description text, all examples (Input/Output/Explanation), all constraints, and any follow-up questions.
Create the file at problems/<topic>/problem_$ARGUMENTS[0].py following the exact skeleton below. Do not zero-pad the number.
After creating the file, run python -m pytest problems/<topic>/problem_$ARGUMENTS[0].py to confirm the tests are collected.
"""
$NUMBER. $TITLE
https://leetcode.com/problems/$SLUG/
$FULL_DESCRIPTION
Example 1:
$EXAMPLE_1
...
Constraints:
$CONSTRAINTS
"""
import pytest
class Solution:
def $METHOD_NAME(self, $PARAMETERS) -> $RETURN_TYPE: ...
@pytest.fixture
def sln():
yield Solution()
@pytest.mark.xfail(reason="Not implemented", strict=True)
def test_001(sln):
"""Test the first example from the problem description."""
assert sln.$METHOD_NAME($ARGS) == $EXPECTED
@pytest.mark.xfail(reason="Not implemented", strict=True)
def test_002(sln):
"""Test the second example from the problem description."""
assert sln.$METHOD_NAME($ARGS) == $EXPECTED
# Add more test functions for remaining examples.
import pytest. Add additional imports from typing only if the method signature requires them (e.g. Optional, Dict).from treenode import TreeNode and use TreeNode.create_from_list() in tests.from linked_lists import ListNode, build_linked_list, linked_list_to_list and use those helpers in tests.Solution method body must be ... — never include an implementation.test_NNN(sln) per example, named sequentially. Each test has a short docstring. Do not use pytest.mark.parametrize.@pytest.mark.xfail(reason="Not implemented", strict=True). Remove the decorator once the solution is implemented.if __name__ == "__main__" block.problems/backtracking/problem_79.py.