LeetCode - 150 - Sliding Window Maximum

The problem You are given an array of integers nums, and there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. Examples Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 Output: [3,3,5,5,6,7] Explanation: Window position Max --------------- ----- [1 3 -1] -3 5 3 6 7 3 1 [3 -1 -3] 5 3 6 7 3 1 3 [-1 -3 5] 3 6 7 5 1 3 -1 [-3 5 3] 6 7 5 1 3 -1 -3 [5 3 6] 7 6 1 3 -1 -3 5 [3 6 7] 7 Input: nums = [1], k = 1 Output: [1] Constraints 1 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 1 <= k <= nums.length Explanation Before we jump into the solution, let’s look at our example with nums = [1,3,-1,-3,5,3,6,7], k = 3 We can see that at the first position we have max value 3, which we add to our output array. ...

June 2, 2025 · 4 min · Dmytro Chumakov

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