Validate One Strict Rise Followed by One Strict Descent
Quick Overview
Validate One Strict Rise Followed by One Strict Descent. Return whether arr is a mountain: it has at least three values, rises strictly to one interior peak, then falls strictly to the end.
Validate One Strict Rise Followed by One Strict Descent
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Return whether `arr` is a mountain: it has at least three values, rises strictly to one interior peak, then falls strictly to the end. Both the rising and falling portions must contain an edge. Equal adjacent values are not allowed.
```cpp
class Solution {
public:
bool validMountainArray(vector<int>& arr);
};
```
### Examples
**Example 1:**
```text
Input: arr = [1,4,7,6,2]
Output: true
Explanation: The sequence rises to7 and then strictly falls to2.
```
**Example 2:**
```text
Input: arr = [1,3,3,1]
Output: false
Explanation: The flat pair at the top prevents a strict rise-and-fall pattern.
```
### Constraints
- `1 <= arr.length <= 10^4`.
- `0 <= arr[i] <= 10^4`.
### Contract considerations
The entire input must form a mountain, not just one of its contiguous subarrays.
```hint Read the boundary condition
After the first non-increasing edge, no later rise is permitted.
```
### Boundary reminders
The entire input must form a mountain, not just one of its contiguous subarrays.
Overview: Validate One Strict Rise Followed by One Strict Descent. Return whether arr is a mountain: it has at least three values, rises strictly to one interior peak, then falls strictly to the end.
Validate One Strict Rise Followed by One Strict Descent
Google
Jun 23, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
Return whether arr is a mountain: it has at least three values, rises strictly to one interior peak, then falls strictly to the end. Both the rising and falling portions must contain an edge. Equal adjacent values are not allowed.
class Solution {
public:
bool validMountainArray(vector<int>& arr);
};
Examples
Example 1:
Input: arr = [1,4,7,6,2]
Output: true
Explanation: The sequence rises to7 and then strictly falls to2.
Example 2:
Input: arr = [1,3,3,1]
Output: false
Explanation: The flat pair at the top prevents a strict rise-and-fall pattern.
Constraints
1 <= arr.length <= 10^4
.
0 <= arr[i] <= 10^4
.
Contract considerations
The entire input must form a mountain, not just one of its contiguous subarrays.
Boundary reminders
The entire input must form a mountain, not just one of its contiguous subarrays.