# MEDIUM

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

## Remove Nth Node From End of List LeetCode Solution | Easy Approach

Remove Nth Node From End of List | Given theÂ headÂ of a linked list, remove theÂ nthÂ node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = …

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

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

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

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

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

## 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 + …

## Zigzag Conversion Leetcode Solution | Easy Approach

Zigzag Conversion | The stringÂ “PAYPALISHIRING”Â is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: “PAHNAPLSIIGYIR” Write the code …

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