```ts
/**
 * Returns an array of the maximum of every contiguous window of k elements in nums.
 * Uses a deque to achieve O(n) time complexity by maintaining indices of potential maxima.
 * @param nums Array of numbers (can include negatives and duplicates)
 * @param k Window size (must be between 1 and nums.length inclusive)
 * @returns Array of maximum values for each sliding window
 */
export function maxSlidingWindow(nums: number[], k: number): number[] {
    if (!Array.isArray(nums) || nums.length === 0) {
        throw new Error("nums must be a non-empty array");
    }
    
    if (!Number.isInteger(k)) {
        throw new Error("k must be an integer");
    }
    
    if (k < 1 || k > nums.length) {
        throw new Error("k must be between 1 and nums.length inclusive");
    }

    const result: number[] = [];
    const deque: number[] = []; // stores indices of elements in decreasing order

    for (let i = 0; i < nums.length; i++) {
        // Remove indices that are out of the current window
        while (deque.length > 0 && deque[0] <= i - k) {
            deque.shift();
        }

        // Remove indices whose corresponding values are less than or equal to current element
        // This maintains decreasing order in the deque
        while (deque.length > 0 && nums[deque[deque.length - 1]] <= nums[i]) {
            deque.pop();
        }

        // Add current index to the deque
        deque.push(i);

        // If we've reached the end of the first window, start adding maximums to result
        if (i >= k - 1) {
            result.push(nums[deque[0]]);
        }
    }

    return result;
}
```