MEDIUM

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

Letter Combinations of a Phone LeetCode Solution | Easy Approach

Letter Combinations of a Phone | Given a string containing digits from¬†2-9¬†inclusive, return all possible letter combinations that the number could represent. Return the answer in¬†any order. A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters. Example 1: Input: digits …

Letter Combinations of a Phone LeetCode Solution | 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 »

String to Integer (atoi) Leetcode Solution | Easy Approach

Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++’s atoi function). The algorithm for myAtoi(string s) is as follows: Read in and ignore any leading whitespace. Check if the next character (if not already at the end of the string) is ‘-‘ or ‘+’. Read this character in if it is either. This determines if the …

String to Integer (atoi) Leetcode Solution | Easy Approach Read More »

Reverse Integer Leetcode Solution | C++ | Java | Python | Easy

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 – 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Example 1: Input: x = 123 Output: 321 Example 2: Input: x = -123 Output: -321 …

Reverse Integer Leetcode Solution | C++ | Java | Python | Easy Read More »

Minimum Cost to Merge Stones

Integer to Roman Leetcode Solution | Easy Approach

Integer to Roman | Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one’s added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + …

Integer to Roman Leetcode Solution | 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 »

x