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

LeetCode - Blind 75 - Missing Number

The problem Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Examples Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums. Input: nums = [0,1] Output: 2 Explanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums. Input: nums = [9,6,4,2,3,5,7,0,1] Output: 8 Explanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums. Constraints n == nums.length 1 <= n <= 10^4 0 <= nums[i] <= n All the numbers of nums are unique. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? ...

May 12, 2025 · 4 min · Dmytro Chumakov