Server Cluster Count
mediumA datacenter rack map is a grid: "1" marks a powered server, "0" marks an empty slot. Servers that touch horizontally or vertically share a network segment and form one cluster.
Given the grid of strings rack, return the number of distinct clusters. Diagonal contact does not connect servers.
Example 1
in rack = [["1","1","0"],["0","1","0"],["0","0","1"]]
out 2
The three 1s in the top-left corner touch and form one cluster; the bottom-right 1 stands alone.
Example 2
in rack = [["0","0"],["0","0"]]
out 0
Constraints
- · 1 <= rows, cols <= 12
- · rack[r][c] is "0" or "1"
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.