Skip to content

Instantly share code, notes, and snippets.

@decagondev
Created April 23, 2025 21:11
Show Gist options
  • Save decagondev/15e6019ca272ad681b0bb9eb772afe39 to your computer and use it in GitHub Desktop.
Save decagondev/15e6019ca272ad681b0bb9eb772afe39 to your computer and use it in GitHub Desktop.

PROBLEM 2: Two Sum

Problem Statement

Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to target.

Concepts Covered

  • Hash Map
  • Brute Force Search

Examples

Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]

Input: nums = [3, 2, 4], target = 6
Output: [1, 2]

Input: nums = [3, 3], target = 6
Output: [0, 1]

Starter Code

def two_sum(nums: list[int], target: int) -> list[int]:
    # Implement your solution here
    pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment