Problem · Array

Find Ideal Days

MediumAmazonFULLTIMEOA
See Amazon hiring insights

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:

  • forecast[i - window] ≥ forecast[i - window + 1] ≥ ... ≥ forecast[i - 1] ≥ forecast[i] ≤ forecast[i + 1] ≤ ... ≤ forecast[i + window] <= forcase[i + window]
  • 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..

    Examples
    01 · Example 1
    forecast = [3, 2, 2, 2, 3, 4]
    window = 2
    return = [3, 4]
    Example 1 illustration
    For a day to qualify as perfect, the rainfall must show a non-increasing pattern over the previous 2 days and a non-decreasing pattern over the following 2 days. Based on the scenario (visual not shown): The rainfall sequence around day 3 follows: day1 ≥ day2 ≥ day3 ≤ day4 ≤ day5, making day 3 an ideal pick. Similarly, the rainfall pattern around day 4 is: day2 ≥ day3 ≥ day4 ≤ day5 ≤ day6, marking day 4 as a valid choice. Hence, the suitable fishing days identified are [3, 4].
    02 · Example 2
    forecast = [1, 0, 1, 0, 1]
    window = 1
    return = [2, 4]
    Those days are perfect fishing days~~ ~ d1 >= d2 <= d3 ~ d3 >= d4 <= d5 What should we return this time? [2, 4].. Enjoy your fishing days! This example was added on 2025-03-20. Source image was attached in the problem source section below..
    03 · Example 3
    forecast = [1, 0, 0, 0, 1]
    window = 2
    return = [3]
    Surprise! We have a perfect fishing day ~~>> d3! d1 >= d2 >= d3 <= d4 <= d5 This example was added on 2025-03-20. Source image was attached in the problem source section below..
    04 · Example 4
    forecast = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    window = 3
    return = [4, 5, 6, 7]
    Those 4 days [4, 5, 6, 7] are perfect for fishing! ~ d1 >= d2 >= d3 >= d4 <= d5 <= d6 <= d7 ~ d2 >= d3 >= d4 >= d5 <= d6 <= d7 <= d8 ~ d3 >= d4 >= d5 >= d6 <= d7 <= d8 <= d9 ~ d4 >= d5 >= d6 >= d7 <= d8 <= d9 <= d10 p.s. I've doubled checked the explanation for you! My eye might have missed something, if you find any mistake, please let me know! I am on the Discord server~ This example was added on 2025-03-20. Source image was attached in the problem source section below..
    Constraints
    1 ≤ windown ≤ 2 * 10^5
    0 ≤ forcast[i] ≤ 10^9
    More Amazon problems
    drafts saved locally
    public int[] findIdealDays(int[] forecast, int window) {
      // write your code here
    }
    
    forecast[3, 2, 2, 2, 3, 4]
    window2
    expected[3, 4]
    sign in to submit