Search⌘ K
AI Features

Problem: Two Sum

Explore how to solve the Two Sum problem with arrays by iterating through pairs of numbers to find those that add up to a target value. Understand the use of nested loops, analyze the O(n²) time complexity, and implement a clear solution in C#.

Statement

Given an array of integers nums and an integer target, find two distinct elements in nums whose sum equals target. Return the indices of these two elements.

You may assume that each input has exactly one valid solution. The same element cannot be used twice. The answer may be returned in any order.

Constraints:

  • 22 \leq nums.Length 104\leq 10^4

  • ...