# Problem Description
The problem involves transforming an initial array of integers over a series of time steps, T. At each time step, the array is expanded by adding elements to both ends. The specific elements added are determined by the values at the ends of the array from the previous time step. The task is to determine the state of the array at a given time step, T.

# Visual Facts
1. **Initial State (T=0)**:
   - Example 1: [5, -1]
   - Example 2: [0, 2]

2. **Transformation Rules**:
   - At each time step, the array is expanded by adding elements to both ends.
   - The leftmost element added is the same as the rightmost element of the previous array.
   - The rightmost element added is the same as the leftmost element of the previous array.

3. **Example 1**:
   - T=0: [5, -1]
   - T=1: [-1, 5, -1, 5]
   - T=2: [5, -1, 5, -1, 5, -1]
   - T=3: [-1, 5, -1, 5, -1, 5, -1, 5]

4. **Example 2**:
   - T=0: [0, 2]
   - T=1: [2, 0, 2, 0]
   - T=2: [0, 2, 0, 2, 0, 2]

# Visual Patterns
1. **Pattern of Expansion**:
   - new_array[0] = previous_array[-1], new_array[-1] = previous_array[0], new_array[1:-1]=previous_array

2. **Element Addition**:
   - The leftmost element added at each step is the same as the rightmost element of the previous array.
   - The rightmost element added at each step is the same as the leftmost element of the previous array.


# Solution
from typing import List

def solution(nums: List[int], T: int) -> List[int]:
    """
    Returns the array at a specified time point T.

    Parameters:
        nums (List[int]): The initial array of integers        
        T (int): The target time point

    Returns:
        List[int]: The array at time T
    """
    new_nums = [_ for _ in nums]
    buffer = [_ for _ in nums]      
    for _ in range(T):
        new_nums.insert(len(buffer), buffer[0])
        new_nums.insert(0, buffer[-1])
        buffer = [_ for _ in new_nums]   

    return new_nums


# Test Script
def test():
    test_cases = [
        ([5,-1], 1, [-1, 5,-1, 5]),
        ([5,-1], 2, [5, -1, 5, -1, 5,-1]),
        ([5,-1], 3, [-1, 5, -1, 5, -1, 5, -1, 5]),
        ([5,-1], 4, [5, -1, 5, -1, 5, -1, 5, -1, 5, -1]),
        ([5,-1], 5, [-1, 5, -1, 5, -1, 5, -1, 5, -1, 5, -1, 5]),
        ([0,3,2], 2, [0, 2, 0, 3, 2 , 0, 2]),
        ([0,3,2], 3, [2, 0, 2, 0, 3, 2 , 0, 2, 0]),
        ([0,3,2], 4, [0, 2, 0, 2, 0, 3, 2 , 0, 2, 0, 2]),
        ([0,3,4,2], 5, [2, 0, 2, 0, 2, 0, 3, 4, 2 , 0, 2, 0, 2, 0]),
        ([0,3,6,4,2], 6, [0, 2, 0, 2, 0, 2, 0, 3, 6, 4, 2 , 0, 2, 0, 2, 0, 2])
    ]
    def equal_arr(arr1, arr2):
        return arr1 == arr2

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

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

test()