Hi there 馃憢

This blog is intended to share my knowledge about software architecture, system design, tools, and techniques for producing high-quality products.

LeetCode - 150 - Min Stack

The problem Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the聽MinStack聽class: MinStack()聽initializes the stack object. void push(int val)聽pushes the element聽val聽onto the stack. void pop()聽removes the element on the top of the stack. int top()聽gets the top element of the stack. int getMin()聽retrieves the minimum element in the stack. You must implement a solution with聽O(1)聽time complexity for each function. ...

June 3, 2025 路 3 min 路 Dmytro Chumakov

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鈥檚 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鈥檚 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鈥檚 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鈥檚 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