JuniorArray

Trionic Array I

You are given an integer array nums of length n.

An array is trionic if there exist indices 0 < p < q < n - 1 such that:

  • nums[0...p] is strictly increasing,
  • nums[p...q] is strictly decreasing,
  • nums[q...n - 1] is strictly increasing.

Return true if nums is trionic, otherwise return false.

Example 1
Inputnums = [1,3,5,4,2,6]
Outputtrue
Pick p = 2 and q = 4, making [1, 3, 5] strictly increasing, [5, 4, 2] strictly decreasing, and [2, 6] strictly increasing.
Example 2
Inputnums = [2,1,3]
Outputfalse
There is no way to pick p and q to form the required three segments.

Constraints

  • 3 <= n <= 100
  • -1000 <= nums[i] <= 1000

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate