2Sum - Complete Tutorial Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report The 2-Sum problem is a popular algorithmic challenge where the goal is to identify two distinct elements in an array whose sum equals a specific target. The problem emphasizes understanding array manipulation and optimizing search operations through hashing. It's a foundational problem used to assess problem-solving skills, particularly in handling array-based tasks and improving performance with hash-based techniques.2Sum on Unsorted InputWhen the array is unsorted, we don’t know anything about the order of the numbers. This means we have to consider every possible pair of numbers to check if they sum up to the target. Hashing and sometimes sorting with two pointer help us in solving these problems efficiently.2Sum (Pair with given sum)Count pairs with given sumPair with given productSum of two elements whose sum is closest to zeroSmallest Difference pair of values between two unsorted ArraysPairs with given sum in doubly linked listAll pairs with a given sum in two unsorted arraysCount pairs with absolute difference equal to k2Sum on Sorted InputWhen the input is sorted, we can take advantage of the order to find the solution more efficiently. Instead of brute force, a more better approach" Two-Pointer Technique" can be used. This method involves using two pointers that move towards each other from the start and end of the array until they find the pair that adds up to the target.2Sum II (Pair with given sum in sorted array)Pair with sum is closest to xClosest number in Sorted arrayPairs with sum is less than targetPair Sum in an Absolute Sorted arrayPair with given sum in a Balanced BSTTwo Sum in BST - Pair with given sumFind the closest pair from two sorted arrays Comment H harendrakumar123 Follow 2 Improve H harendrakumar123 Follow 2 Improve Article Tags : DSA Hash two-pointer-algorithm Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 15 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like