Katkat

Find longest segment with dominant ends

AmazonSoftware Engineer · Online Assessment

Last 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.