3952. Trionic Array I
My accepted Python solution to LeetCode problem 3952, Trionic Array I, running in 57ms.
- Difficulty: Easy
- Python
- Runtime 57ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 57ms, memory 17.5MB, accepted 2026-01-02.
class Solution:
def isTrionic(self, nums: List[int]) -> bool:
n = len(nums)
if n < 3:
return False
# Find peaks (local maxima) and valleys (local minima)
for p in range(1, n-1):
for q in range(p+1, n-1):
# Check if nums[0..p] is strictly increasing
inc1 = True
for i in range(p):
if nums[i] >= nums[i+1]:
inc1 = False
break
if not inc1:
continue
# Check if nums[p..q] is strictly decreasing
dec = True
for i in range(p, q):
if nums[i] <= nums[i+1]:
dec = False
break
if not dec:
continue
# Check if nums[q..n-1] is strictly increasing
inc2 = True
for i in range(q, n-1):
if nums[i] >= nums[i+1]:
inc2 = False
break
if inc1 and dec and inc2:
return True
return False