2Sum - Complete Tutorial Last Updated : 22 Feb, 2025 Comments Improve Suggest changes Like Article 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 More infoAdvertise with us Next Article 2Sum - Complete Tutorial H harendrakumar123 Follow Improve Article Tags : Algorithms DSA Hash two-pointer-algorithm Practice Tags : AlgorithmsHashtwo-pointer-algorithm Similar Reads Complete Roadmap To Learn DSA Mastering DSA enables developers to write optimized code that performs well even with large datasets. The very first step in the journey is the selection of a complete roadmap. This guide provides a structured path, starting from basic concepts to advanced topics. It offers practical steps, resource 5 min read Game Development with Unity | Introduction Game Development: The article "Do you want to make your own games?" introducing the basic concept of game development. As mentioned in the article, Unity is one of the most popular game engines for both 2D and 3D games. You don't need to have a strong understanding of physics or mathematics to devel 3 min read Unity | Introduction to Interface The article "Game Development with Unity | Introduction" introduces about Unity and how to install it. In this article, we will see how to create a new project and understand the interface of the Unity Game Editor. Creating a new project Open the Unity Hub. Click on New button at the top right. Sele 3 min read 5 Steps to Learn to Code in Any Programming Language Suppose you want to dive deep into machine learning, but you didn't know Python or you want to switch to Full Stack Development and worried that you never code with JavaScript, well this is the common problems students often faced when they want to explore a new exciting field in computer science. A 9 min read OLA Cabs Interview Experience | Set 2 (For Android - 1.5 Years) First Round Written Test 1) Implement Stack Operations. Also maintain count of Largest Integer present in Stack at any given point of Time. 2) Implement Minesweeper Game. 3) Design an Android application to emulate Countdown .. Take Input from the User and start counting down from entered value till 2 min read Like