Count Healthy Service Instances
ServiceNow platforms often feature dashboards that provide a real-time overview of critical system health and performance. A common visualization component is a grid or matrix representing various service instances, where each cell indicates the current operational status of a specific instance. To quickly gauge the overall health of a system or a particular service cluster, it's essential to count how many of these instances are currently running without issues.
This problem simulates a simplified version of such a health monitoring scenario. You are tasked with processing a health grid and determining the total number of healthy service instances.
Implement a function countHealthyServiceInstances that takes a 2D array (matrix) of integers, healthGrid, as input. Each element in the grid will be either 0 or 1, where 1 signifies a 'healthy' service instance and 0 signifies an 'unhealthy' instance. Your function should return the total count of healthy service instances across the entire grid.
healthGrid: A number[][] (or int[][] in other languages) representing the health status of various service instances. Each inner array represents a row, and elements within it represent columns. Each element healthGrid[r][c] will be either 0 or 1.number (or int) representing the total count of 1s found in the healthGrid.healthGrid will always contain at least one row, and each row will contain at least one column. All rows will have the same length, forming a valid rectangular matrix.healthGrid are guaranteed to be either 0 or 1.Examples
Example 1
Input:
healthGrid = [[0,1,0],[1,1,1],[0,0,1]]
Output:
5
Note:
There are five '1's in the grid: healthGrid[0][1], healthGrid[1][0], healthGrid[1][1], healthGrid[1][2], and healthGrid[2][2].
Example 2
Input:
healthGrid = [[0,0],[0,0]]
Output:
0
Note:
There are no '1's in the grid, so the count of healthy instances is 0.
Example 3
Input:
healthGrid = [[1]]
Output:
1
Note:
The grid contains a single healthy service instance.
Constraints
1 <= healthGrid.length <= 100 (number of rows)1 <= healthGrid[i].length <= 100 (number of columns)healthGrid[i][j] will always be 0 or 1.Loading editor...