# Problem Description
The problem involves validating elements in an array based on their relationships with adjacent elements. Given a list of integers and an index, we need to determine if the element at that index satisfies certain conditions to be considered "valid" according to mathematical comparison rules with its neighboring elements.

# Visual Facts
1. Image shows three examples with arrays of different lengths:
   - Example 1: [3, -7]
   - Example 2: [3, -1, 0, 2, -2, 7]
   - Example 3: [-3, 7, -2, 4, -6, -5, 3]

2. Each element has a validation result marked as either "VALID" or "INVALID"

3. Each validation shows a mathematical comparison using >, or ≤ operators

4. The comparisons involve the current element and adjacent elements or expressions

# Visual Patterns
1. Pattern of Validation:
   - When marked VALID:
     * The element is greater than its neighbor(s) or combination of neighbors
     * Uses ">" operator
     * Example: "3>-7" is VALID
     * Example: "7>-2" is VALID

   - When marked INVALID:
     * Uses "≤" operator
     * Element is less than or equal to some combination of neighbors
     * Example: "-7≤3" is INVALID

2. Comparison Rules:
   - For edge elements (first or last in array):
     * Compare with just one adjacent element
     * Example: First element 3>-1 is VALID

   - For middle elements:
     * Compare with expressions involving both adjacent elements
     * Example: "4>-2+(-6)" is VALID

3. Key Pattern Discovery:
   - An element is VALID if and only if it is strictly greater than the sum of its adjacent elements
   - For edge elements, compare with the single adjacent element
   - For middle elements, compare with the sum of both adjacent elements


# Solution
from typing import List

def solution(nums: List[int], idx: int) -> bool:
    """
    Determines if the element at the given index in the list is valid based on the specified pattern.
    Parameters:
        nums (List[int]): the list of numbers.
        idx (int): Zero-based index of the element to check.

    Returns:
        bool: True if the element is valid, False otherwise.
    """
    len_nums = len(nums)
    if idx == 0 or idx == len_nums - 1:
        return nums[0] > nums[1] if idx == 0 else nums[-1] > nums[-2]
    return nums[idx] > nums[idx - 1] + nums[idx + 1]


# Test Script
def test():
    test_cases = [
        ([3,-1,0,2,-2,7,-3,1], 0, True),
        ([3,-1,0,2,-2,7,-3,1], 2, False),
        ([3,-1,0,2,-2,7,-3,1], 4, False),
        ([3,-1,0,2,-2,7,-3,1], 3, True),
        ([3,-1,0,2,-2,7,-3,1], 7, True),
        ([3,-1,0,2,-9,-7], 4, False),
        ([3,-1,0,2,-9,-7], 5, True),
        ([-3, 7, -2, 4, -6, -5, 3, -2, 7, 3],2, False),
        ([-3, 7, -2, 4, -6, -5, 3, -2, 7, 3],7, False),
        ([-3, 7, -2, 4, -6, -5, 3, -2, 7, 3],6, True),
    ]

    for nums, idx, expected_output in test_cases:
        try:
            output = solution(nums, idx)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`nums`: {nums}\n"
                f"`idx`: {idx}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`nums`: {nums}\n"
                f"`idx`: {idx}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()