Dsa
Dynamic Programming
Medium
Maximal Consecutive Bad Days
You are organizing a series of events over a period of days. Each day can be marked as good or bad, and you can have at most 'k' bad days in a row before it's impossible to hold the events. Given an array of integers representing the status of each day (1 for good, 0 for bad) and an integer k, return the maximum number of consecutive days you can hold events without exceeding 'k' bad days.
Input format:
- The first line contains an integer n (number of days).
- The second line contains n space-separated integers (0 or 1) representing the days.
- The third line contains an integer k (maximum allowed consecutive bad days).
Output format:
- A single integer representing the maximum length of the segment of days where you can still hold events.
Example:
Input:
7
1 0 0 1 1 0 1
1
Output:
5
Key concepts
dynamic_programmingarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now