Ctrl K

A Trend That Never Turns

Easy
The array prices holds an item's price day by day. Say the price moves one way if over the whole period it either never went down **or** never went up (staying flat is allowed). Return True if the price moves one way, and False otherwise.
Example 1
prices=[3, 3, 5, 8, 8] → True

The price never went down, so it moves one way.

Example 2
prices=[9, 4, 4, -2] → True

The price never went up.

Example 3
prices=[1, 5, 2] → False

First a rise, then a drop: the trend changed direction.

Constraints
  • 1 ≤ len(prices) ≤ 10⁵
  • -10⁵ ≤ prices[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
prices=[3, 3, 5, 8, 8]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 154 tests on the server, hidden ones included.