Code Logo

Equinox Gate Verdict

Published at05 Jan 2026
Easy 3 views
Like30

In Equinox Gate Verdict, you are given an array of numbers and need to return a yes-or-no answer based on how each neighboring pair compares.

The judge behavior for this export is: return true when every adjacent pair differs by at most 1. Return false as soon as you find a jump larger than 1. Arrays with zero or one element automatically return true because there is no neighboring pair that can break the rule.

For example, nums = [1,2,3,4] returns true because every step changes by exactly 1. The array [2,2,2,2] also returns true because adjacent values differ by 0. But [10,20,30] returns false because the jump from 10 to 20 is already too large.

So the task is to scan the array from left to right and confirm that no adjacent pair differs by more than 1.

Example Input & Output

Example 1
Input
nums = [1,2,3,4]
Output
true
Explanation

Each neighboring pair differs by at most 1, so the array passes the check.

Example 2
Input
nums = [10,20,30]
Output
false
Explanation

The jump from 10 to 20 is greater than 1, so the check fails immediately.

Example 3
Input
nums = [2,2,2,2]
Output
true
Explanation

Equal neighbors differ by 0, which is still allowed.

Algorithm Flow

Recommendation Algorithm Flow for Equinox Gate Verdict
Recommendation Algorithm Flow for Equinox Gate Verdict

Solution Approach

The simplest way to solve this problem is to walk through the array once and compare each number with the one immediately before it. If the absolute difference between any neighboring pair is greater than 1, you can return false right away. If you reach the end without finding such a jump, return true.

The reason this works is that the condition is local. The array passes only when every adjacent pair stays close together. That means you do not need sorting, dynamic programming, or any extra memory. One bad neighboring pair is enough to fail the whole array, so early exit is both correct and efficient.

In JavaScript, the core logic looks like this:

for (let i = 1; i < nums.length; i++) {
  if (Math.abs(nums[i] - nums[i - 1]) > 1) {
    return false;
  }
}
return true;

The use of Math.abs is important because the rule should work in both directions. A jump from 1 to 4 and a jump from 4 to 1 are both differences of 3, so both should fail. Using the absolute value makes the comparison direction-agnostic and keeps the code easy to read.

This approach matches the visible test patterns. In [1, 2, 3, 4], each adjacent difference is 1, so the array passes. In [2, 2, 2, 2], each adjacent difference is 0, so it also passes. In [10, 20, 30], the first adjacent difference is 10, so the array fails immediately.

Edge cases are simple too. An empty array returns true because there are no pairs to violate the rule. A one-element array also returns true. The time complexity is O(n) because you inspect each adjacent pair once, and the space complexity is O(1) because you only use a loop variable and direct comparisons.

So the full strategy is: compare each number with the previous one, measure the absolute difference, return false if any difference exceeds 1, and return true if the whole scan finishes cleanly.

Best Answers

java
class Solution {
    public boolean is_sorted_asc(int[] nums) {
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i+1]) return false;
        }
        return true;
    }
}