/**
* Problem: LeetCode 3637 - Trionic Array I
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public boolean isTrionic(int[] nums) {
int n = nums.length;
if (n < 4) {
return false;
}
int i = 0;
// Phase 1: Strictly increasing to peak p
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
int p = i;
if (p == 0 || p >= n - 2) {
return false;
}
// Phase 2: Strictly decreasing to valley q
while (i + 1 < n && nums[i] > nums[i + 1]) {
i++;
}
int q = i;
if (q == p || q >= n - 1) {
return false;
}
// Phase 3: Strictly increasing to the end
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
return i == n - 1;
}
}
"""
Problem: LeetCode 3637 - Trionic Array I
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
from typing import List
class Solution:
def isTrionic(self, nums: List[int]) -> bool:
n = len(nums)
if n < 4:
return False
i = 0
# Phase 1: Strictly increasing to peak p
while i + 1 < n and nums[i] < nums[i + 1]:
i += 1
p = i
if p == 0 or p >= n - 2:
return False
# Phase 2: Strictly decreasing to valley q
while i + 1 < n and nums[i] > nums[i + 1]:
i += 1
q = i
if q == p or q >= n - 1:
return False
# Phase 3: Strictly increasing to the end
while i + 1 < n and nums[i] < nums[i + 1]:
i += 1
return i == n - 1
/**
* Problem: LeetCode 3637 - Trionic Array I
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
using namespace std;
class Solution {
public:
bool isTrionic(vector<int>& nums) {
int n = nums.size();
if (n < 4) {
return false;
}
int i = 0;
// Phase 1: Strictly increasing to peak p
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
int p = i;
if (p == 0 || p >= n - 2) {
return false;
}
// Phase 2: Strictly decreasing to valley q
while (i + 1 < n && nums[i] > nums[i + 1]) {
i++;
}
int q = i;
if (q == p || q >= n - 1) {
return false;
}
// Phase 3: Strictly increasing to the end
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
return i == n - 1;
}
};
/**
* Problem: LeetCode 3637 - Trionic Array I
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
/**
* @param {number[]} nums
* @return {boolean}
*/
var isTrionic = function(nums) {
const n = nums.length;
if (n < 4) {
return false;
}
let i = 0;
// Phase 1: Strictly increasing to peak p
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
const p = i;
if (p === 0 || p >= n - 2) {
return false;
}
// Phase 2: Strictly decreasing to valley q
while (i + 1 < n && nums[i] > nums[i + 1]) {
i++;
}
const q = i;
if (q === p || q >= n - 1) {
return false;
}
// Phase 3: Strictly increasing to the end
while (i + 1 < n && nums[i] < nums[i + 1]) {
i++;
}
return i === n - 1;
};