Maximum of Subarray Minimums
Updated
Problem statement
You are given an integer array arr of length n and an integer k.
Consider every contiguous subarray of length k:
- The first subarray is
arr[0..k-1]. - The next subarray is
arr[1..k], and so on. - The last subarray ends at index
n-1.
For each such subarray, find its minimum value. Among all these minimum values, determine and return the maximum one.
Implement maxOfSubarrayMinimums with these parameters:
int[] arr: the input arrayint k: the length of every contiguous subarray
Return an int: the maximum among the minimum values of all length-k subarrays.
Function
maxOfSubarrayMinimums(arr: int[], k: int) → intExamples
Example 1
arr = [1,2,3,4,5]k = 2return = 4- The length-
2subarrays are[1,2],[2,3],[3,4], and[4,5]. - Their minimum values are
1,2,3, and4. - The maximum of these values is
4.
Constraints
1 <= n <= 10^61 <= arr[i] <= 10^9for0 <= i < n1 <= k <= n
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Minimum of Fixed-Window MaximaJuspay · OA
- Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
- Most Negative Number in Each WindowWells Fargo · OAWells Fargo interview questions
- Maximum of Fixed-Window MinimaRoblox · OARoblox interview questions
- Incident MonitorStripe · OAStripe interview questions
- Sliding Window Maximum in a MatrixCitadel · OACitadel interview questions
- Maximum Earnings Across WarehousesAmazon · ONSITE INTERVIEW
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
- Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions
JP Morgan Chase interview experiences
- JPMorgan Chase Experienced SWE Java Interview: 1 Experience
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)