Loading...
Loading...
A hostel warden keeps a record of n days for a student. Each day is P (on time) or L (late). The student wants to show the longest run of consecutive days with at most k late days in it.
Print the length of the longest such run. If every run has too many late days, print 0.
P or L.Example 1
Input
10 2 PPLPLLPPLP
Output
5
Days 6 to 10 (LPPLP) have exactly 2 late days, and so do days 1 to 5. Both have length 5.
Example 2
Input
4 0 LLLL
Output
0
Every day is late and no late day is allowed.
Try the problem first. Open one hint at a time.
Keep a run of days from left to right and a count of late days inside it.
Move right forward one day at a time. If the late count goes above k, move left forward until it is k again.
After fixing the run, its length right - left + 1 is a candidate answer.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor