entry: id: 1 title: two-sum params: nums: type: array items: type: int target: type: int call: cpp: "Solution().twoSum({nums}, {target})" rust: "Solution::two_sum({nums}, {target})" python3: "Solution().twoSum({nums}, {target})" python2: "Solution().twoSum({nums}, {target})" ruby: "two_sum({nums}, {target})" java: "new Solution().twoSum({nums}, {target})" csharp: "new Solution().TwoSum({nums}, {target})" kotlin: "Solution().twoSum({nums}, {target})" go: "twoSum({nums}, {target})" dart: "Solution().twoSum({nums}, {target})" swift: "Solution().twoSum({nums}, {target})" typescript: "twoSum({nums}, {target})" judge: type: exact limits: time_ms: 1000 memory_mb: 256 oracle: python3: call: "Checker().twoSum(nums, target, {result})" checker: | class Checker: def twoSum(self, nums, target, result): if not isinstance(result, list) or len(result) != 2: return False i, j = result if not isinstance(i, int) or not isinstance(j, int): return False if i == j: return False if i < 0 or j < 0 or i >= len(nums) or j >= len(nums): return False return nums[i] + nums[j] == target seed: 42 tests: - name: Example 1 in: nums: - 2 - 7 - 11 - 15 target: 9 out: - 0 - 1 - name: Example 2 in: nums: - 3 - 2 - 4 target: 6 out: - 1 - 2 - name: Example 3 in: nums: - 3 - 3 target: 6 out: - 0 - 1 - name: Two elements positive in: nums: - 1 - 2 target: 3 out: - 0 - 1 - name: Two elements negative in: nums: - -1 - -2 target: -3 out: - 0 - 1 - name: Zero pair in: nums: - 0 - 4 - 3 - 0 target: 0 out: - 0 - 3 - name: Negative and positive in: nums: - -5 - 8 - 12 - 7 target: 3 out: - 0 - 1 - name: Pair at front in: nums: - 9 - 1 - 2 - 3 target: 10 out: - 0 - 1 - name: Pair at end in: nums: - 5 - 11 - 7 - 13 target: 20 out: - 2 - 3 - name: Pair in middle in: nums: - 8 - 4 - 6 - 1 - 9 target: 7 out: - 2 - 3 - name: Duplicates simple in: nums: - 3 - 3 - 5 - 9 target: 6 out: - 0 - 1 - name: Duplicates many in: nums: - 2 - 3 - 5 - 7 - 11 target: 13 out: - 0 - 4 - name: Mixed duplicates in: nums: - 1 - 5 - 1 - 8 - 9 target: 14 out: - 1 - 4 - name: Large positive values in: nums: - 1000000000 - -1000000000 - 17 - 23 target: 40 out: - 2 - 3 - name: Extreme sum in: nums: - 1000000000 - -999999999 - -1 target: 1 out: - 0 - 1 - name: Extreme negative sum in: nums: - -1000000000 - 999999999 - 2 target: -1 out: - 0 - 1 - name: Target zero with signs in: nums: - -8 - 8 - 15 - -3 target: 0 out: - 0 - 1 - name: Small ascending in: nums: - 1 - 4 - 6 - 10 - 14 target: 20 out: - 2 - 4 - name: Small descending in: nums: - 14 - 10 - 6 - 4 - 1 target: 15 out: - 0 - 4 - name: Negative target in: nums: - -10 - -20 - 5 - 30 target: 10 out: - 1 - 3 - name: Solution uses repeated value later in: nums: - 4 - 1 - 4 - 9 target: 8 out: - 0 - 2 - name: Pair with zero and positive in: nums: - 0 - 7 - 11 - 15 target: 7 out: - 0 - 1 - name: Pair with zero and negative in: nums: - 0 - -7 - 11 - 15 target: -7 out: - 0 - 1 - name: Multiple possible values but unique indices in: nums: - 6 - 1 - 8 - 2 - 11 - 17 target: 13 out: - 3 - 4 - name: Pair near lower bound in: nums: - -1000000000 - 2 - 999999998 - 7 target: -2 out: - 0 - 2 - name: Pair near upper bound in: nums: - 1000000000 - -2 - -999999998 - 7 target: 999999998 out: - 0 - 1 - name: Longish array 1 in: nums: - 1 - 4 - 7 - 10 - 13 - 16 - 100 target: 113 out: - 4 - 6 - name: Longish array 2 in: nums: - 2 - 5 - 11 - 19 - 23 - 37 - 200 target: 205 out: - 1 - 6 - name: Longish array 3 in: nums: - -12 - -4 - 3 - 8 - 14 - 25 - 100 target: 88 out: - 0 - 6 - name: Longish array 4 in: nums: - 100 - 200 - 300 - 400 - 500 - 900 target: 1300 out: - 3 - 5 - name: Longish array 5 in: nums: - -50 - -40 - -20 - -10 - 0 - 10 - 70 target: 20 out: - 0 - 6 - name: Longish array 6 in: nums: - 5 - 15 - 25 - 35 - 45 - 1000 target: 1045 out: - 4 - 5 - name: Longish array 7 in: nums: - 12 - 24 - 36 - 48 - 60 - 72 - 99 target: 111 out: - 0 - 6 - name: Longish array 8 in: nums: - 19 - 3 - 14 - 27 - 6 - 33 - 100 target: 133 out: - 5 - 6 - name: Longish array 9 in: nums: - -1 - 1 - -2 - 2 - -3 - 3 - 50 target: 49 out: - 0 - 6 - name: Longish array 10 in: nums: - 101 - 202 - 303 - 404 - 505 - 1000 target: 1505 out: - 4 - 5 - name: Longish array 11 in: nums: - 7 - 14 - 21 - 28 - 35 - 42 - 100 target: 121 out: - 2 - 6 - name: Longish array 12 in: nums: - -100 - -1 - 50 - 52 - 98 - 150 target: 149 out: - 1 - 5 - name: Longish array 13 in: nums: - 1000 - 2000 - 3000 - 4000 - 5000 - 9000 target: 14000 out: - 4 - 5 - name: Longish array 14 in: nums: - 42 - 17 - 8 - 23 - 4 - 15 - 16 - 100 target: 116 out: - 6 - 7