Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
Beginner · 20 XP

Two Sum in Linear Time

Given an array of integers `nums` and an integer `target`, return the indices of the two numbers such that they add up to `target`. ### Constraints: - Exactly one valid solution exists. - Time complexity must be O(N) using a dictionary lookup table.

Show Step-by-Step Hint
  • • As you iterate, calculate `complement = target - num`.
  • • Check if `complement` is already in your dictionary.
Type: Code Challenge
Runtime: PYTHON
PYTHON solutionCHALLENGE #4
Solutions and scores are stored in your private attempt history.Sign in to submit challenge