Two Pointer Make String a Subsequence Using Cyclic Increments Solution In C++/Java/Python/JS Make String a Subsequence Using Cyclic Increments Problem Description: You are given two 0-indexed strings str1 and str2. In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a'
Largest Merge Of Two Strings Solution In C++/Java/Python/JS Problem Description You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options: If word1 is non-empty, append the first character in word1 to merge and delete it from
Reverse Words in a String III Solution In C++/Java/Python/JS Problem Description: Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Examples: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat edoCteeL tsetnoc" Input: s = "Mr Ding&
Reverse Words in a String Solution In C++/Java/Python/JS Problem Description: Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order, concatenated by a single space. Note
4Sum Solution In C++/Java/Python/JS Problem Description Given an array nums of nn 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 indices nums[a] + nums[b] + nums[c] + nums[d]
Find All K-Distant Indices in an Array Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed integer array nums and two integers key and k. An index i in the array is said to be k-distant if there exists at least one index j such that: * |i - j| <= k, and * nums[j] == key In simple terms, a
Two Pointer Apply Operations to an Array Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed array nums of size n that contains non-negative integers. The goal is to apply a sequence of operations to this array and return the final result after all transformations are complete. For each index i from 0 to n - 2, you need
Remove Element Solution In C++/Java/Python/JS Problem Description Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are
Rearrange Array Elements by Sign Problem Description You are given a 0-indexed integer array nums of even length consisting of an equal number of positive and negative integers. You should return the array of nums such that the array follows the given conditions: 1. Every consecutive pair of integers has opposite signs. 2. For all
Sort Colours Solution In C++/Java/Python/JS Problem Description Given an array nums with nn objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors appearing in the order red, white, and blue. We will use the integers 0, 1, and 2 to represent the colors:
3Sum Closest Solution In C++/Java/Python/JS Problem Description Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to the target. Return the sum of the three integers. You may assume that each input would have exactly one solution. Examples: Input : nums = [-1,
3 Sum Solution In C++/Java/Python/JS Problem Description 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. Examples: Input : nums = [-1, 0, 1,
Sort Array By Parity II Solution In C++/Java/Python/JS Sort Array By Parity II Problem Description: Given an array of integers nums, half of the integers in nums are odd, and the other half are even. Sort the array so that whenever nums[i] is odd, i is odd, and whenever nums[i] is even, i is even.Return
Reverse Vowels of a String Solution In C++/Java/Python/JS Problem Description Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once. Example
Shortest Distance to a Character Solution Code in C++/Java/Python/JavaScript Problem Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The distance between two indices i and j
Lexicographically Smallest Palindrome Solution Code in C++/Java/Python/JavaScript Problem You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter. Your task is to make s a palindrome with the minimum number of operations
Partition Array According to Given Pivot Solution Code in C++/Python/Java/JS Problem You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied: Every element less than pivot appears before every element greater than pivot. Every element equal to pivot appears in between the elements less than and greater than pivot.
Move Pieces to Obtain a String Problem Description You are given two strings start and target, both of length n. Each string consists only of the characters 'L', 'R', and '_' where: The characters 'L' and 'R' represent pieces, where a piece 'L' can move
Next Permutation Problem Description A permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following are all the permutations of arr: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,
Next Greater Element III Problem Description Given a positive integer n, find the smallest integer which has exactly the same digits existing in the integer n and is greater in value than n. If no such positive integer exists, return -1. Note that the returned integer should fit in 32-bit integer, if there is
Sentence Similarity III Problem Description You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and lowercase English characters. Two sentences s1
Rotate Array Problem Description Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,
Sort Array By Parity Problem Statement Given an integer array nums, move all the even integers at the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. Examples Input: nums = [3,1,2,4] Output: [2,4,3,1] Explanation: The outputs [4,2,3,1]
Two Pointer Two Sum Solution In C++/Java/Python/JS Problem Description 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 will have exactly one solution, and you may not use the same element twice. You can return the answer
Watering Plants II Problem Description Alice and Bob want to water n plants in their garden. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. Each plant needs a specific amount of water.