File size: 3,986 Bytes
0225ffc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from pydantic import BaseModel, Field
from typing import Optional, Any

class QuestionCreate(BaseModel):
    """
    Schema for creating or adding a new coding question to the database.
    """
    id: Optional[int] = Field(
        None,
        description="Optional custom identifier for the question. If not provided, it will be auto-incremented.",
        example=42
    )
    title: str = Field(
        ...,
        description="The display name or title of the coding problem.",
        example="Two Sum"
    )
    difficulty: str = Field(
        ...,
        description="Difficulty tier. Must be 'easy', 'medium', or 'hard'.",
        example="easy"
    )
    category: str = Field(
        ...,
        description="The category of the question, e.g. 'Arrays', 'Recursion', 'Dynamic Programming'.",
        example="Arrays"
    )
    problem_description: Optional[str] = Field(
        None,
        description="The detailed markdown-formatted problem description.",
        example="Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`."
    )
    starter_code: Optional[str] = Field(
        None,
        description="The template code provided to the user in the IDE when they load the question.",
        example="def twoSum(nums: list[int], target: int) -> list[int]:\n    pass"
    )
    example_input: Optional[str] = Field(
        None,
        description="Sample input scenario details.",
        example="nums = [2,7,11,15], target = 9"
    )
    example_output: Optional[str] = Field(
        None,
        description="Expected output for the sample input.",
        example="[0,1]"
    )
    example_reasoning: Optional[str] = Field(
        None,
        description="Step-by-step logic explaining the sample output.",
        example="Because nums[0] + nums[1] == 2 + 7 == 9, we return [0, 1]."
    )
    learn_content: Optional[str] = Field(
        None,
        description="Additional training / learning material or hints about the question.",
        example="Learn about hashing techniques to solve this in O(N) time complexity."
    )
    solution_code: Optional[str] = Field(
        None,
        description="The reference solution code in Python to verify user submissions.",
        example="def twoSum(nums, target):\n    seen = {}\n    for i, num in enumerate(nums):\n        if target - num in seen:\n            return [seen[target - num], i]\n        seen[num] = i\n    return []"
    )
    test_cases: Optional[Any] = Field(
        None,
        description="A list of objects containing inputs and outputs for sandbox test suites. Can be a JSON array or dict.",
        example=[{"input": [[2, 7, 11, 15], 9], "output": [0, 1]}]
    )
    function_name: Optional[str] = Field(
        None,
        description="The entrypoint function name used in the evaluation script to test user code.",
        example="twoSum"
    )

    class Config:
        json_schema_extra = {
            "example": {
                "id": 1,
                "title": "Two Sum",
                "difficulty": "easy",
                "category": "Arrays",
                "problem_description": "Given an array of integers nums and an integer target...",
                "starter_code": "def twoSum(nums, target):\n    pass",
                "example_input": "nums = [2,7,11,15], target = 9",
                "example_output": "[0,1]",
                "example_reasoning": "Because 2 + 7 == 9, we return [0, 1].",
                "learn_content": "Use a hash map to reduce time complexity from O(n^2) to O(n).",
                "solution_code": "def twoSum(nums, target):\n    seen = {}\n    for i, n in enumerate(nums):\n        diff = target - n\n        if diff in seen:\n            return [seen[diff], i]\n        seen[n] = i",
                "test_cases": [{"input": [[2, 7, 11, 15], 9], "output": [0, 1]}],
                "function_name": "twoSum"
            }
        }