left
and right
, of the same length as the security
array, to store the lengths of the non-increasing and non-decreasing sequences, respectively.left
array by iterating from left to right. For each index i
, if security[i]
is less than or equal to security[i-1]
, increment the count from the previous index; otherwise, reset the count to 1.right
array by iterating from right to left. For each index i
, if security[i]
is less than or equal to security[i+1]
, increment the count from the next index; otherwise, reset the count to 1.security
array and check for each day i
if left[i]
and right[i]
are both greater than time
. If so, add the day i
to the list of good days.