Interview Questions/Coding/Circular Rest Streak

Circular Rest Streak

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Circular Rest Streak

A monitoring schedule is circular: after the last slot, the next slot is the first slot again. Each slot is 1 for rest and 0 for work. Find the longest contiguous rest streak that may wrap around the end of the schedule, but the streak cannot use more than n slots total. Input Format: The first line contains t, the number of test cases. Each test case contains n followed by n binary slot values. Output Format: For each test case, print the maximum rest streak length.

Examples

Example 1
Input:
1
5
1 0 1 1 1
Output:
4

Explanation: The three rest slots at the end can connect to the rest slot at the beginning, giving a circular streak of length 4.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp