>_
Compiler Shell v1.0.4
Connection to data node secure.
Parsed 600 algorithm challenges.
Mounted telemetry indexes.
> Launching prep command center...
Compiling 0%
Easy 💻 Coding

[Machine Learning] Two Sum Pattern

Problem Statement

Problem Statement for Two Sum Pattern under Machine Learning:

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
Back to Curriculum