# Array

## 3Sum LeetCode Solution | Easy Approach | C++, Java, Python

3Sum LeetCode | Given an integer array nums, return all the tripletsÂ [nums[i], nums[j], nums[k]]Â such thatÂ i != j,Â i != k, andÂ j != k, andÂ nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Example 2: Input: nums = [] Output: [] …

## 4Sum LeetCode Solution | C++, Java, Python | Easy Approach

4Sum | Given an arrayÂ numsÂ ofÂ nÂ integers, returnÂ an array of all theÂ uniqueÂ quadrupletsÂ [nums[a], nums[b], nums[c], nums[d]]Â such that: 0 <= a, b, c, d < n a, b, c, and d are distinct. nums[a] + nums[b] + nums[c] + nums[d] == target You may return the answer in any order. Example 1: Input: nums = [1,0,-1,0,-2,2], target = 0 Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]] Example 2: Input: nums = …

## 3Sum Closest LeetCode Solution | C++, Java, Python | Easy Approach

3Sum Closest | Given an integer arrayÂ numsÂ of lengthÂ nÂ and an integerÂ target, find three integers inÂ numsÂ such that the sum is closest toÂ target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Example 1: Input: nums = [-1,2,1,-4], target = 1 Output: 2 Explanation: The sum that is closest to …

## Container With Most Water Leetcode Solution | Easy Approach

Container With Most Water | You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that …

## Median of Two Sorted Arrays LeetCode Solution | Easy Approach

Median of Two Sorted Arrays | Given two sorted arraysÂ nums1Â andÂ nums2Â of sizeÂ mÂ andÂ nÂ respectively, returnÂ the medianÂ of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: …

## Two Sum Leetcode Optimal Solution | C++ | Java | Python

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because …