LeetCode - 150 - Redundant Connection

The problem In this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with n nodes labeled from 1 to n, with one additional edge added. The added edge has two different vertices chosen from 1 to n, and was not an edge that already existed. The graph is represented as an array edges of length n where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the graph. ...

November 5, 2025 · 5 min · Dmytro Chumakov

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