score
to 0 and res
(result) to 0.seen
to store the first occurrence of each score.hours
array:
a. Increment score
by 1 if the current day is tiring, else decrement by 1.
b. If score
is positive, update res
to the current index + 1.
c. If score
is not in seen
, add it with the current index.
d. If score - 1
is in seen
, update res
to the maximum of res
and the difference between the current index and the index stored in seen
for score - 1
.res
.