|
| 1 | +{ |
| 2 | + "problem_name": "two_sum", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "1", |
| 5 | + "problem_title": "Two Sum", |
| 6 | + "difficulty": "Easy", |
| 7 | + "topics": "Array, Hash Table", |
| 8 | + "_tags": { "list": ["grind-75"] }, |
| 9 | + "readme_description": "Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.\n\nYou may assume that each input would have exactly one solution, and you may not use the same element twice.\n\nYou can return the answer in any order.", |
| 10 | + "_readme_examples": { |
| 11 | + "list": [ |
| 12 | + { |
| 13 | + "content": "```\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\n```\n**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]." |
| 14 | + }, |
| 15 | + { "content": "```\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n```" }, |
| 16 | + { "content": "```\nInput: nums = [3,3], target = 6\nOutput: [0,1]\n```" } |
| 17 | + ] |
| 18 | + }, |
| 19 | + "readme_constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.", |
| 20 | + "readme_additional": "**Follow-up:** Can you come up with an algorithm that is less than O(n^2) time complexity?", |
| 21 | + "helpers_imports": "", |
| 22 | + "helpers_content": "", |
| 23 | + "helpers_run_name": "two_sum", |
| 24 | + "helpers_run_signature": "(solution_class: type, nums: list[int], target: int)", |
| 25 | + "helpers_run_body": " implementation = solution_class()\n return implementation.two_sum(nums, target)", |
| 26 | + "helpers_assert_name": "two_sum", |
| 27 | + "helpers_assert_signature": "(result: list[int], expected: list[int]) -> bool", |
| 28 | + "helpers_assert_body": " assert result == expected\n return True", |
| 29 | + "solution_imports": "", |
| 30 | + "solution_contents": "", |
| 31 | + "solution_class_content": "", |
| 32 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .helpers import assert_two_sum, run_two_sum\nfrom .solution import Solution", |
| 33 | + "test_content": "", |
| 34 | + "test_class_name": "TwoSum", |
| 35 | + "test_class_content": " def setup_method(self):\n self.solution = Solution()", |
| 36 | + "_solution_methods": { |
| 37 | + "list": [ |
| 38 | + { |
| 39 | + "name": "two_sum", |
| 40 | + "signature": "(self, nums: list[int], target: int) -> list[int]", |
| 41 | + "body": " # TODO: Implement two_sum\n return []" |
| 42 | + } |
| 43 | + ] |
| 44 | + }, |
| 45 | + "_test_helper_methods": { |
| 46 | + "list": [{ "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" }] |
| 47 | + }, |
| 48 | + "_test_methods": { |
| 49 | + "list": [ |
| 50 | + { |
| 51 | + "name": "test_two_sum", |
| 52 | + "signature": "(self, nums: list[int], target: int, expected: list[int])", |
| 53 | + "parametrize": "nums, target, expected", |
| 54 | + "test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2]), ([3, 3], 6, [0, 1]), ([2, 5, 5, 11], 10, [1, 2]), ([1, 2, 3, 4, 5], 8, [2, 4]), ([0, 4, 3, 0], 0, [0, 3]), ([-1, -2, -3, -4, -5], -8, [2, 4]), ([1, 3, 4, 2], 6, [2, 3])]", |
| 55 | + "body": " result = run_two_sum(Solution, nums, target)\n assert_two_sum(result, expected)" |
| 56 | + } |
| 57 | + ] |
| 58 | + }, |
| 59 | + "playground_imports": "from helpers import run_two_sum, assert_two_sum\nfrom solution import Solution", |
| 60 | + "playground_setup": "# Example test case\nnums = [2, 7, 11, 15]\ntarget = 9\nexpected = [0, 1]", |
| 61 | + "playground_run": "result = run_two_sum(Solution, nums, target)\nresult", |
| 62 | + "playground_assert": "assert_two_sum(result, expected)" |
| 63 | +} |
0 commit comments