Previous Greater Element

Given an integer array nums, return an array where answer[i] is the nearest value strictly greater than nums[i] among positions to its left. Return -1 when no…

Given an integer array `nums`, return an array where `answer[i]` is the nearest value strictly greater than `nums[i]` among positions to its left. Return `-1` when no strictly greater value exists to the left.

- `1 <= nums.length <= 100000` - `-1000000000 <= nums[i] <= 1000000000` - Equal values are not strictly greater.

Example 1: input nums = [4,5,2,10,8]; output [-1,-1,5,-1,10]. The nearest greater value before 2 is 5, and before 8 it is 10.

Example 2: input nums = [2,2,3,2]; output [-1,-1,-1,3]. Equal 2 values do not qualify as greater.

Category: Stack. Topic: stack. Difficulty: Medium. Patterns: monotonic-stack.