Previous Smaller Element
Given an integer array nums, return an array where answer[i] is the nearest value strictly smaller 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 smaller than `nums[i]` among positions to its left. Return `-1` when no strictly smaller value exists to the left.
- `1 <= nums.length <= 100000` - `-1000000000 <= nums[i] <= 1000000000` - Equal values are not strictly smaller.
Example 1: input nums = [4,5,2,10,8]; output [-1,4,-1,2,2]. The nearest smaller value before 10 is 2, and 2 is also nearest before 8.
Example 2: input nums = [2,2,1,2]; output [-1,-1,-1,1]. Equal 2 values do not qualify as smaller.
Category: Stack. Topic: stack. Difficulty: Medium. Patterns: monotonic-stack.