Graph Theory37 sections · 1633 units
Open in Course

Problem - Implement Solution

(LeetCode 1584)

Implement the solution using Prim's algorithm. Start with point 00. Expand the MST by adding the nearest point at each step. Test the solution on the sample inputs. Make sure you compute Manhattan distance correctly.

Check that the total cost matches the expected output. If you prefer Kruskal, you can generate all edges and sort them. Both approaches work, but Prim is more space-efficient for this problem.