All Posts

Leetcode 2476: Closest Nodes Queries in a Binary Search Tree

You are given the root of a binary search tree (BST) and an array of queries. For each query, find the largest value smaller than or equal to the query value and the smallest value greater than or equal to the query value in the tree.

Leetcode 2477: Minimum Fuel Cost to Report to the Capital

A country network consists of n cities connected by n-1 bidirectional roads. The capital city is city 0, and each city has one representative with a car having a fixed number of seats. Calculate the minimum amount of fuel required for all representatives to reach the capital city.

Leetcode 2492: Minimum Score of a Path Between Two Cities

You are given a set of cities, each connected by bidirectional roads. Each road has a distance, and the score of a path between two cities is defined as the minimum distance of any road on that path. The task is to find the minimum score of a path between city 1 and city n. You are allowed to visit the cities multiple times, and the roads may be repeated.

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 2641: Cousins in Binary Tree II

Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins’ values. Two nodes are cousins if they have the same depth but different parents. The depth of a node is the number of edges from the root to the node.