Graphs

Matrix Island Perimeter

February 25, 2024
medium
Graphs

Problem Statement: # Given a 2D grid of 0s and 1s, where 1 represents land and 0 represents water, find the perimeter of the island. The grid cells are connected horizontally/vertically (not diagonally). There is exactly one island, and it doesn’t have lakes (water inside that isn’t connected to the water around the island). The grid is surrounded by water, and there is exactly one island (i.e., one or more connected land cells). ...

Maximum Path Quality of a Graph

February 4, 2024
medium
Graphs, DFS

Problem Statement # Given a weighted undirected graph with n vertices numbered from 0 to n-1, represented by an array edges where edges[i] = [from_i, to_i, weight_i] denotes a bidirectional and weighted edge between nodes from_i and to_i. Each node has a value values[i] representing its value. You start traversing the graph from node 0 and collect values. You can visit each node at most once. However, you can revisit node 0 any number of times. ...