Given an integer array nums, find the length of the longest contiguous segment [i..j] (j−i+1 ≥ 2) such that both endpoints are strictly greater than every element strictly between them; i.e., max(nums[i+1..j−1]) < min(nums[i], nums[j]). Return only the length. Examples: nums=[1,3,2,4,1] → longest is [3,2,4], length 3; nums=[4,2,6] → [4,2,6], length 3. Brute force is not allowed—design an algorithm faster than O(n^ 2) and provide complexity analysis.