Subarray Maximum Element Length

Asked at Moloco · Coding Questions · Difficulty: Medium · Last asked Jul 15, 2026

Given an array of integers `nums`, define an array `ans` of the same length as `nums`, where `ans[i]` is the maximum length of a subarray `nums[L..R]` such that the maximum element in that subarray is equal to `nums[i]`. Return the array `ans`.

Loading the problem…