You are given an integer array nums.
An element nums[i] is considered valid if it satisfies at least one of the following conditions:
It is the first element or the last element of the array.
nums[i] is strictly greater than every element to its left.
nums[i] is strictly greater than every element to its right.
Return an array containing all valid elements in the order they appear in nums.
Constraints:
nums.length
nums[i]
You are given an integer array nums.
An element nums[i] is considered valid if it satisfies at least one of the following conditions:
It is the first element or the last element of the array.
nums[i] is strictly greater than every element to its left.
nums[i] is strictly greater than every element to its right.
Return an array containing all valid elements in the order they appear in nums.
Constraints:
nums.length
nums[i]