Array

Minimum Cost to Merge Stones

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: [] …

3Sum LeetCode Solution | Easy Approach | C++, Java, Python Read More »

Minimum Cost to Merge Stones

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 = …

4Sum LeetCode Solution | C++, Java, Python | Easy Approach Read More »

Minimum Cost to Merge Stones

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 …

3Sum Closest LeetCode Solution | C++, Java, Python | Easy Approach Read More »

Minimum Cost to Merge Stones

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 …

Container With Most Water Leetcode Solution | Easy Approach Read More »

Minimum Cost to Merge Stones

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: …

Median of Two Sorted Arrays LeetCode Solution | Easy Approach Read More »

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 …

Two Sum Leetcode Optimal Solution | C++ | Java | Python Read More »

x