All Posts

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 2658: Maximum Number of Fish in a Grid

You are given a 2D matrix grid of size m x n, where each cell can either be a land cell (represented by 0) or a water cell (represented by a positive integer indicating the number of fish present in that cell). A fisher can start at any water cell and perform two operations any number of times: catch all the fish in the current cell or move to an adjacent water cell. Your task is to determine the maximum number of fish the fisher can catch if they start at the optimal water cell.

Leetcode 2685: Count the Number of Complete Components

You are given a graph with n vertices, numbered from 0 to n-1. The graph contains undirected edges described in a 2D array edges, where each element edges[i] = [ai, bi] indicates that there is an undirected edge between vertices ai and bi. A connected component is a subgraph in which there is a path between any two vertices, and no vertex is connected to vertices outside of the subgraph. A connected component is said to be complete if there is an edge between every pair of vertices in that component. Your task is to return the number of complete connected components in the graph.

Leetcode 2812: Find the Safest Path in a Grid

You are given a square grid of size n x n, where each cell contains either a thief (represented by 1) or is empty (represented by 0). You start at the top-left corner of the grid and must find the maximum safeness factor for a path to the bottom-right corner. The safeness factor is defined as the minimum Manhattan distance from any cell in the path to the nearest thief.

Leetcode 2948: Make Lexicographically Smallest Array by Swapping Elements

You are given a list of integers, nums, and a positive integer limit. In each operation, you can choose two indices i and j and swap the elements at these indices if the absolute difference between nums[i] and nums[j] is less than or equal to the given limit. Your task is to return the lexicographically smallest array that can be obtained after applying the operation as many times as needed.