Coding Sandbox • Python
Python Coding Challenge
45:00
Problems:
Python 3.11 Runtime10 Points
Problem 1 of 5Arrays & Hash Maps
EASY**Two Sum**
Given a list of integers `nums` and an integer `target`, return the indices of the two numbers that add up to `target`.
You may assume that each input has exactly one solution, and you may not use the same element twice.
Return the answer as a list of two indices (0-based), in any order.
Constraints:
2 <= len(nums) <= 10^4 -10^9 <= nums[i] <= 10^9 Exactly one valid answer exists.
Example Test Cases:
Input: {"function": "two_sum", "args": [[2, 7, 11, 15], 9]}
Expected Output: [0, 1]
Note: nums[0] + nums[1] = 2 + 7 = 9
Input: {"function": "two_sum", "args": [[3, 2, 4], 6]}
Expected Output: [1, 2]
Note: nums[1] + nums[2] = 2 + 4 = 6
Input: {"function": "two_sum", "args": [[3, 3], 6]}
Expected Output: [0, 1]
Note: nums[0] + nums[1] = 3 + 3 = 6
solution.py
Code is executed against visible & hidden test cases server-side.Press Tab for indentation