Skip to content

Enhance /problem GET route #4

Description

@DavidUlloa6310

We need to enhance /problem route by:

  1. Returning a random problem every time the route is called.
  2. Creating a /problem/(problemID) route.

For returning a random problem, create an array in problem.py containing 3 different questions from LeetCode (with an easy difficulty). Then, in the /problem route (the function itself is called index), return a random selection from the array.

Also important is the information of the problem itself. Please update the information for each problem to contain:

{
        "id": 1,
        "title": "Two Sum",
        "difficulty": "Easy",
        "objectives": [
            "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
            "You may assume that each input would have exactly one solution, and you may not use the same element twice.",
            "You can return the answer in any order."
        ],
        "examples": [
            {
            "input": "nums = [2,7,11,15], target = 9",
            "output": "[0,1]",
            "explanation": "Because nums[0] + nums[1] == 9, we return [0, 1]."
            },
            {
            "input": "nums = [3,2,4], target = 6",
            "output": "[1,2]"
            },
            {
            "input": "nums = [3,3], target = 6",
            "output": "[0,1]"
            }
        ],
        "starterCode": "def twoSum(nums: List[int], target: int) -> List[int]:\n\t# Code here...\n\tpass",
        # NEW FIELDS
        time: "T00:05:00",  # AMOUNT OF TIME PLAYER HAS FOR THE QUESTION,
        testCases: [{ # CASES THE USER CODE IS GOING TO BE CHECKED WITH
            "inputs": [[2,7,11,15], 9] 
            "output": [0,1]
        }, {
            "inputs": [[3,2,4], 6]
            "output": [1,2]
        }, {
            "inputs": [[3,3], 6]
            "output": [0,1]
        }],
        "functionName" : "twoSum",
              
    }

Last step is to create a /problem/(problemID) route that returns the problem with id equal to problemID. The id will be the index of the problem in the array.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions