QUICK START:HTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsDSASystem DesignDevOpsCybersecurityAI / ML
AlgorithmEasy Solved

Two Sum (Array Hash Map Lookup)

Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target` in O(n) time.

Requirements:

  • Return an array of two indices [i, j].
  • Each input will have exactly one solution.
  • You may not use the same element twice.
  • Achieve O(n) time complexity using a Hash Map.
Sample Input:
nums = [2, 7, 11, 15], target = 9
Sample Output:
[0, 1]
javascript• Solution Editor
EXECUTION CONSOLE Tests Passed (+75 XP)
Click “Run & Test Code” to execute your solution against test cases.