An electronic trading floor at Two Sigma consists of automated quantitative trading desks numbered to . Some desks share direct private high-frequency communication links, while others communicate indirectly through intermediate desks.
Desk connectivity is represented as an binary adjacency matrix is_connected where is_connected[i][j] == 1 indicates a direct bidirectional communication link between desk and desk , and is_connected[i][j] == 0 indicates no direct link. Direct links are symmetric (is_connected[i][j] == is_connected[j][i]) and reflective (is_connected[i][i] == 1).
A trading cluster is a maximal connected component of trading desks where any desk in the cluster can communicate with any other desk in the cluster directly or indirectly.
Your Task
Implement the function count_trading_clusters(is_connected: list[list[int]]) -> int that returns the total number of disjoint, independent trading clusters operating on the floor.
Constraints
is_connected[i][j] is either or .is_connected[i][i] == 1 for all .is_connected[i][j] == is_connected[j][i] for all .Examples
is_connected = [
[1, 1, 0],
[1, 1, 0],
[0, 0, 1]
]
# Desk 0 and 1 are connected. Desk 2 is isolated.
# Output: 2