LeetCode - 150 - Course Schedule II

The problem There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1] indicates that to take course 0 you have to first take course 1. Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array. ...

October 30, 2025 · 5 min · Dmytro Chumakov

LeetCode - 150 - Surrounded Regions

The problem You are given an m x n matrix board containing letters 'X' and 'O', capture regions that are surrounded: Connect: A cell is connected to adjacent cells horizontally or vertically. Region: To form a region connect every 'O' cell. Surround: The region is surrounded with 'X' cells if you can connect the region with 'X' cells and none of the region cells are on the edge of the board. To capture a surrounded region, replace all 'O's with 'X's in-place within the original board. You do not need to return anything. ...

October 21, 2025 · 3 min · Dmytro Chumakov

LeetCode - 150 - Rotting Oranges

The problem You are given an m x n grid where each cell can have one of three values: 0 representing an empty cell, 1 representing a fresh orange, or 2 representing a rotten orange. Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return -1. ...

October 17, 2025 · 5 min · Dmytro Chumakov

LeetCode - 150 - Walls and Gates

The problem You are given an m*n 2D grid initialized with these three possible values: -1 - A wall or obstacle. 0 - A gate. INF - Infinity means an empty room. We use the value 2^31 - 1 = 2147483647 to represent INF. Fill each empty room with the distance to its nearest gate. If it’s impossible to reach the gate, it should be filled with INF. Assume the grid can only be traversed up, down, left, or right. ...

October 11, 2025 · 4 min · Dmytro Chumakov

LeetCode - 150 - Max Area of Island

The problem You are given an m x n binary matrix grid. An island is a group of 1s (representing land) connected 4-directionally (horizontally or vertically). You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value 1 in the island. Return the maximum area of an island in grid. If there is no island, return 0. ...

October 6, 2025 · 3 min · Dmytro Chumakov