Easy
💻 Coding
[Algorithms] Two Sum Pattern
Problem Statement
Problem Statement for Two Sum Pattern under Algorithms:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
Input Constraints:
- 1 <= len(nums) <= 10^5
- Elements fit in memory standard spaces.
Proposed Solution
def twoSum(nums, target):
seen = {}
for i, num in enumerate(nums):
remaining = target - num
if remaining in seen:
return [seen[remaining], i]
seen[num] = i
return []
Your Progress
Pending Completion
Save Progress?
Login to sync your solutions across all dynamic local and remote sessions.
Join Techlance