Leetcode 547. Number of Provinces
Given an n x n symmetric adjacency matrix where isConnected[i][j]=1 denotes a direct undirected edge between cities, count the number of connected components (provinces) formed by direct or indirect connections. This is effectively finding the number of connected components in a graph — solvable with DFS/BFS or Union-Find.
Asked at:
Amazon
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Early November, 2024
Amazon
Mid-level
Design a data structure to represent country alliances with the following operations: 1) Initialize with a list of country pairs representing alliances, 2) Check if two countries are allies directly or indirectly, 3) Add a new alliance between two countries, 4) Return the number of distinct groups of allied countries
Hello Interview Premium
Your account is free and you can post anonymously if you choose.