Longest Streak of Days Where All Microservices Pass Health Checks

Quick Overview

Given a grid of daily health-check results for several microservices, find the longest run of consecutive days on which every service passed. The problem tests scanning a 2D array by column and tracking a running streak that resets on any failure.

Longest Streak of Days Where All Microservices Pass Health Checks

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given `reports`, a 2D array of size `M x N`, where `M` is the number of microservices and `N` is the number of days. `reports[i][j]` is `1` if microservice `i` passed its health check on day `j`, and `0` if it failed. Return the length of the longest consecutive streak of days on which all microservices reported a pass. ### Function Signature ```python def longest_health_streak(reports: list[list[int]]) -> int: ``` ### Rules - `reports[i]` holds the results of microservice `i`, one entry per day, and every row has the same length `N`. - A day belongs to a streak only when every microservice has `1` in that day's column. - If no day has every microservice passing, return `0`. ### Constraints - `1 <= M <= 100` - `1 <= N <= 10^5` - `reports[i][j]` is either `0` or `1` ### Examples ```text Input: reports = [[1,1,1,0,1,1],[1,1,0,0,1,1],[1,1,1,1,1,1]] Output: 2 ``` Days 0 and 1 are all-pass (streak of 2). Day 2 fails because service 1 reports `0`, and day 3 fails because services 0 and 1 report `0`. Days 4 and 5 are all-pass again, so the longest streak is 2. ```text Input: reports = [[1,1,1,1],[1,1,1,1]] Output: 4 ``` Both services pass on every day, so all 4 days form one streak. ```text Input: reports = [[1,0],[0,1]] Output: 0 ``` Each service passes on one day, but never on the same day, so no day is all-pass.

Overview: Given a grid of daily health-check results for several microservices, find the longest run of consecutive days on which every service passed. The problem tests scanning a 2D array by column and tracking a running streak that resets on any failure.

Salesforce logo
Salesforce
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given reports, a 2D array of size M x N, where M is the number of microservices and N is the number of days. reports[i][j] is 1 if microservice i passed its health check on day j, and 0 if it failed.

Return the length of the longest consecutive streak of days on which all microservices reported a pass.

Function Signature

def longest_health_streak(reports: list[list[int]]) -> int:

Rules

  • reports[i] holds the results of microservice i , one entry per day, and every row has the same length N .
  • A day belongs to a streak only when every microservice has 1 in that day's column.
  • If no day has every microservice passing, return 0 .

Constraints

  • 1 <= M <= 100
  • 1 <= N <= 10^5
  • reports[i][j] is either 0 or 1

Examples

Input: reports = [[1,1,1,0,1,1],[1,1,0,0,1,1],[1,1,1,1,1,1]]
Output: 2

Days 0 and 1 are all-pass (streak of 2). Day 2 fails because service 1 reports 0, and day 3 fails because services 0 and 1 report 0. Days 4 and 5 are all-pass again, so the longest streak is 2.

Input: reports = [[1,1,1,1],[1,1,1,1]]
Output: 4

Both services pass on every day, so all 4 days form one streak.

Input: reports = [[1,0],[0,1]]
Output: 0

Each service passes on one day, but never on the same day, so no day is all-pass.