LeetCode - 150 - Permutation in String

The problem Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. A permutation is a rearrangement of all the characters of a string. In other words, return true if one of s1’s permutations is a substring of s2. Examples Input: s1 = "ab", s2 = "eidbaooo" Output: true Explanation: s2 contains one permutation of s1 ("ba"). Input: s1 = "ab", s2 = "eidboaoo" Output: false Constraints 1 <= s1.length, s2.length <= 10^4 s1 and s2 consist of lowercase English letters. Explanation Before we jump into the solution, let’s take a look at the example with input s1 = "ab", s2 = "eidbaooo" We are looking for a permutation of s1 in s2 with the size of s1. In the example, we can see that we have a permutation of s1 = "ab" in s2 = "eidbaooo" but in a different order. ...

May 28, 2025 · 5 min · Dmytro Chumakov

LeetCode - 150 - Trapping Rain Water

The problem Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Examples Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Input: height = [4,2,0,3,2,5] Output: 9 Constraints n == height.length 1 <= n <= 2 * 10^4 0 <= height[i] <= 10^5 Explanation Let’s look at our example and determine the algorithm of how much water each position could trap. ...

May 23, 2025 · 5 min · Dmytro Chumakov

LeetCode - 150 - Two Sum II - Input Array Is Sorted

The problem Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length. Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. The tests are generated such that there is exactly one solution. You may not use the same element twice. ...

May 19, 2025 · 4 min · Dmytro Chumakov

LeetCode - 150 - Valid Sudoku

The problem Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be valid but is not necessarily solvable. Only the filled cells need to be validated according to the mentioned rules. Examples ...

May 16, 2025 · 4 min · Dmytro Chumakov

LeetCode - Blind 75 - Sum of Two Integers

The problem Given two integers a and b, return the sum of the two integers without using the operators + and -. Examples Input: a = 1, b = 2 Output: 3 Input: a = 2, b = 3 Output: 5 Constraints -1000 <= a, b <= 1000 Explanation From the description of the problem, we learn that we need to figure out the way of adding two numbers without using + or - operators. Let’s visualize this problem and find the way we can do it. ...

May 14, 2025 · 3 min · Dmytro Chumakov