Problem · Array
Even-Position Monotonicity
Learn this problemProblem statement
Given an array of non-negative integers numbers, inspect the values at zero-based even indices: numbers[0], numbers[2], numbers[4], and so on.
- Return
"increasing"if these values are in strictly increasing order. - Return
"decreasing"if these values are in strictly decreasing order. - Return
"none"if these values are not strictly monotonic.
Values at odd indices do not affect the result.
A solution with time complexity not worse than O(numbers.length^2) fits within the execution time limit.
Function
solution(numbers: int[]) → StringExamples
Example 1
numbers = [12,65,15,72,19,72]return = "increasing"The values at even indices are 12, 15, and 19. Since 12 < 15 < 19, the result is "increasing".
Example 2
numbers = [12,1,54,5,19,14]return = "none"The values at even indices are 12, 54, and 19. They first increase and then decrease, so the result is "none".
Example 3
numbers = [666,17,66,5,6,23]return = "decreasing"The values at even indices are 666, 66, and 6. Since 666 > 66 > 6, the result is "decreasing".
Constraints
numbers.length >= 3.- Every
numbers[i]is a non-negative integer that fits in a 32-bit signed integer.