FastPrepFind Ideal Days
Problems/Find Ideal Days

Find Ideal Days

Amazon logoAmazon● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A virtual assistant is being given a feature that recommends ideal days for fishing from a rainfall forecast.

A day is ideal when rainfall is non-increasing throughout the previous window days leading to that day and non-decreasing throughout the following window days.

Given the predicted rainfall for the next n days in forecast, find every ideal day. Formally, an array index i is ideal when:

forecast[i - window] ≥ forecast[i - window + 1] ≥ … ≥ forecast[i - 1] ≥ forecast[i] ≤ forecast[i + 1] ≤ … ≤ forecast[i + window - 1] ≤ forecast[i + window]

Return the ideal day numbers in ascending order. Array index i represents day i + 1, so returned day numbers are 1-based. At least one ideal day is guaranteed.

Function

findIdealDays(forecast: int[], window: int) → int[]

Examples

Example 1

forecast = [3, 2, 2, 2, 3, 4]window = 2return = [3, 4]
Example 1 illustration

With window = 2, day 3 satisfies 3 ≥ 2 ≥ 2 ≤ 2 ≤ 3, and day 4 satisfies 2 ≥ 2 ≥ 2 ≤ 3 ≤ 4. Therefore, return [3, 4].

Example 2

forecast = [1, 0, 1, 0, 1]window = 1return = [2, 4]

With window = 1, day 2 satisfies 1 ≥ 0 ≤ 1, and day 4 satisfies 1 ≥ 0 ≤ 1. Therefore, return [2, 4].

Example 3

forecast = [1, 0, 0, 0, 1]window = 2return = [3]

Day 3 is the only day with two complete days on both sides, and it satisfies 1 ≥ 0 ≥ 0 ≤ 0 ≤ 1. Therefore, return [3].

Example 4

forecast = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]window = 3return = [4, 5, 6, 7]

All rainfall values are equal, so equality satisfies both required trends. Every day with three complete days on both sides is ideal: days 4, 5, 6, and 7.

Constraints

  • 1 ≤ window ≤ n ≤ 2 × 105
  • 0 ≤ forecast[i] ≤ 109

More Amazon Online Assessment questions

  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Get Smallest Base SegmentOA · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • Minimum Grid InconvenienceOA · Seen Nov 2026
  • Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
  • Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Two SumOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
  • Count Subarrays Matching a Comparison PatternCapital One · OACapital One interview questions
  • Count Subarrays with at Least K Equal-Fruit PairsTikTok · OATikTok interview questions
  • Consistent LogsRippling · OARippling interview questions
  • Minimum Team Size From Every StartCognizant · OA
  • Minimum of Fixed-Window MaximaJuspay · OA
  • Sliding-Window Means with IEEE Special ValuesHeadlands Technologies · OAHeadlands Technologies interview questions
  • Maximum Decrypted ScoreMicrosoft · OAMicrosoft interview questions

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int[] findIdealDays(int[] forecast, int window) {
      // write your code here
    }

}
Checking account…