Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike

All past online assesments of Google can be found using the tag "google_oa" in the search bar.

Here is the link :

in Online Assessments by Expert (34,270 points) | 997 views

1 Answer

0 like 0 dislike

Rose Garden

You are planting onions to make salads. Given an array of positive integers that indicates the day that each of your onion is ready for harvest, the minimum number of adjacent mature onions required for a salad, and the number of salads you want to make, return the earliest day that you can finish making all salads. If it is impossible to make the required number of salads, return -1.


  • onions: an array of positive integers. Onion i will be ready for harvest on day onions[i].
  • k: the minimum number of adjacent onions required to make a salad.
  • n: the number of salads you want to make.


Return the earliest day that you can finish making n salads, or -1 if the task is impossible.


Example 1:


1onions = [1, 2, 6, 10, 3, 4, 1] 2k = 2 3n = 2



Day 1: [h, o, o, o, o, o, h]

The first and last onions are ready for harvest.

Day 2: [h, h, o, o, o, o, h]

The second onion matures, and the first 2 mature onions can be used to make a salad.

Day 3: [h, h, o, o, h, o, h]

Day 4: [h, h, o, o, h, h, h]

The last 3 onions make a salad, meeting the required n = 2 salads. So day 4 is the earliest day to finish making the required number of salads.


  • 1 <= onions.length == 10^5
  • 1 <= onions[i] <= 10^9
  • 1 <= n <= 10^6
  • 1 <= k <= onions.length
by Expert (34,270 points)