Find longest segment with dominant ends
AmazonSoftware Engineer · Online AssessmentLast updated
This question evaluates algorithmic problem-solving with arrays and complexity-aware design, testing skills in efficient subarray identification, boundary reasoning, and performance analysis within the Coding & Algorithms domain.
Question
Given an integer array nums, find and return the length of the longest contiguous subarray such that the first and last elements of the subarray are strictly greater than every element that appears between them. Brute-force enumeration of all subarrays is not acceptable; design an algorithm that avoids TLE on large inputs.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.