All Posts

Leetcode 2545: Sort the Students by Their Kth Score

You are given a matrix of scores, where each row represents a student and each column represents an exam. You need to sort the students based on their scores in the k-th exam, from the highest to the lowest. Return the sorted matrix.

Leetcode 2556: Disconnect Path in a Binary Matrix by at Most One Flip

You are given a binary matrix grid where you can move from any cell (row, col) to adjacent cells (row + 1, col) or (row, col + 1) only if they have the value 1. The grid is disconnected if there is no path from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1). You are allowed to flip at most one cell (changing a 1 to 0 or vice versa), but you cannot flip the cells (0, 0) or (m - 1, n - 1). Return true if it is possible to disconnect the grid by flipping at most one cell, otherwise return false.

Leetcode 2596: Check Knight Tour Configuration

Given an n x n chessboard, the knight starts at the top-left corner and visits every cell exactly once. The knight’s movements are represented by a grid where grid[row][col] indicates the order of the knight’s visit to that cell. Determine if this sequence of moves is valid, i.e., the knight moves according to its legal movement pattern.

Leetcode 2614: Prime In Diagonal

Given a 2D grid of integers, you need to determine the largest prime number present on any of the diagonals of the grid. A number is considered prime if it is greater than 1 and divisible only by 1 and itself. The diagonal elements are those where the row and column indices are the same or sum to the length of the grid minus 1.

Leetcode 2639: Find the Width of Columns of a Grid

You are given a 0-indexed m x n integer matrix grid. The width of a column is determined by the length of its longest integer. For example, the length of an integer is defined as the number of digits in its absolute value, with an additional digit for negative numbers. For each column, return its width, which is the maximum length of any integer in that column.

Leetcode 2643: Row With Maximum Ones

Given a binary matrix of size m x n, your task is to find the row that contains the highest number of 1’s. If there are multiple rows with the same count of 1’s, return the row with the smallest index. The output should contain the index of the row and the count of 1’s in that row.