Two Sum

Two Pointers & Sliding Window DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Find if two numbers in an array sum to a target (Two Sum Problem) and return YES/NO or indices., Arrays, Loops, Conditional Statements, Time Complexity, Space Complexity, Big O Notation, Hashing, Hash Tables, Map, Sorting, Two Pointers, brute force, sorting algorithms, hash map, array traversal, time complexity analysis, two pointer technique, Hashing & Hash Maps.

Two Sum Problem Given an array of integers arr[] and an integer target. Solve the following two variants of the problem: Variant 1: Return YES if there exist two distinct numbers in the array such that their sum is equal to the target. Otherwise, return NO. Variant 2: Return the 0 based indices of the two distinct numbers such that their sum is equal to the target. If no such pair exists, return { 1, 1}. Note: You are not allowed to use the same element twice. For example, if the target is equal to 6 and arr[1] = 3, then arr[1] + arr[1] = target is not a valid solution. Examples: Example 1: Example 2: