| Random Link ¯\_(ツ)_/¯ | ||
| Jul 21, 2024 | » | Shortest Path in a Grid w/ Obstacles Elimination
6 min; updated Jul 21, 2024
Shortest Path in a Grid with Obstacles Elimination - LeetCode. leetcode.com . Accessed Jul 21, 2024. Problem You are given an \(m \times n\) grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum number of steps to walk from the upper left corner \((0, 0)\) to the lower-right corner \((m-1, n-1)\) given that you can eliminate at most \(k\) obstacles.... |
| Jul 21, 2024 | » | Minimum Penalty for a Shop
4 min; updated Jul 21, 2024
Minimum Penalty for a Shop. leetcode.com . Accessed Jul 21, 2024. Problem You are given the customer visit log of a shop represented by a zero-indexed string customers consisting only of characters N and Y. If the \(i^{th}\) character is Y, it means that customers come at the \(i^{th}\) hour, whereas N indicates that no customers come at the \(i^{th}\) hour. If the shop closes at the \(j^{th}\) hour (\(0 \le j \le n\)), the penalty is calculated as follows:... |
| Jul 20, 2024 | » | Minimizing Bottom-Right Paths in a 2xN Grid
4 min; updated Jul 20, 2024
Grid Game - LeetCode. leetcode.com . Accessed Jul 20, 2024. Problem You are given a 0-indexed 2D array grid of size \(2 \times n\), where grid[r][c] represents the number of points at position \((r, c)\) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at \((0, 0)\) and want to reach \((1, n-1)\). Each robot may only move to the right or down.... |
| Aug 1, 2022 | » | Sorting and Searching
5 min; updated Aug 1, 2022
Order Statistics K-th Smallest Element in Sorted Matrix Given an \(N \times N\) matrix, where each of the rows and columns are sorted in ascending order, return the \(k^{th}\) smallest element in the matrix. The memory complexity must be better than \(O(N^2)\). It’s not guaranteed that matrix[r][c] > matrix[r-1][c], so we can’t compute the row (and similarly, the column) in which the \(k^{th}\) smallest element is in. Using a priority queue that holds the \(K\) smallest elements does not work because the memory usage is \(O(K)\), where \(K\) can be any value in \([1, N^2]\).... |
| Jul 31, 2022 | » | Unique Paths to the Bottom-Right Corner w/ Obstacles
2 min; updated Jul 31, 2022
Problem Starting from the top-left corner, what is the number of possible unique paths to reach the bottom-right corner, if you can only move either down or right at any point in time, and the path cannot include any square that is an obstacle? Solution The addition of obstacles has these implications: I can’t use the combinatorics formula because the problem is no longer easy to define in general terms.... |
| Jul 31, 2022 | » | Spanning 4-Directional Walks From Origin to Destination w/ Obstacles
3 min; updated Jul 31, 2022
Problem Given an \(M \times N\) integer array grid where grid[i][j] could be: 1 representing the starting square. There is exactly one starting square. 2 representing the ending square. There is exactly one ending square. 0 representing empty squares that we can walk over. -1 representing obstacles that we cannot walk over. Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.... |