Find Ideal Days
Learn this problemProblem statement
Banana, Amazon’s super intelligent virtual assistant, simplifies tasks such as configuring your Banana-supported gadgets, playing podcast, delivering weather forecasts, and more. The development team is crafting a new feature that recommends the best days for fishing based on weather predictions.
Based on recent research, a day qualifies as suitable for fishing if the rainfall levels have been non-increasing over the past "window" days leading up to that specific day and are non-decreasing during the following "window" days after it.
You are given the projected rainfall amounts for the next n days in a list called forecast. Your task is to identify all days that meet this criterion. Formally, a day is ideal if the following condition holds true:
Return a list of such ideal days, sorted in ascending order. Remember, the i-th element in the forecast array corresponds to the data for day i + 1 (1-based reference).
✅ Note: There is always at least one valid ideal day guaranteed.
Parameters:
forecast[n]: A list of integers representing the predicted rainfall amount for each upcoming day.
window: Just an integer..
Function
findIdealDays(forecast: int[], window: int) → int[]Examples
Example 1
forecast = [3, 2, 2, 2, 3, 4]window = 2return = [3, 4]
Example 2
forecast = [1, 0, 1, 0, 1]window = 1return = [2, 4]Example 3
forecast = [1, 0, 0, 0, 1]window = 2return = [3]Example 4
forecast = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]window = 3return = [4, 5, 6, 7]Constraints
window ≤ n ≤ 2 * 10^50 ≤
forcast[i] ≤ 10^9