Tap here to switch tabs
Problem
Submissions

Problem: Valid Elements in an Array

Valid Elements in an Array asks you to return the elements that are endpoints or strictly greater than every element on their left or right, preserving array order.

Statement

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:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Valid Elements in an Array

Valid Elements in an Array asks you to return the elements that are endpoints or strictly greater than every element on their left or right, preserving array order.

Statement

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:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100