```ts
/**
 * Returns an array of the maximum value in every contiguous window of size k.
 * Uses a deque to maintain indices of potential maxima for O(n) time complexity.
 * 
 * @param nums - Array of numbers to process
 * @param k - Window size (must be between 1 and nums.length inclusive)
 * @returns Array of maximum values for each window position
 */
export function maxSlidingWindow(nums: number[], k: number): number[] {
    if (!Array.isArray(nums) || nums.length === 0) {
        throw new Error('Invalid input: nums must be a non-empty array');
    }
    
    if (typeof k !== 'number' || !Number.isInteger(k)) {
        throw new Error('Invalid window size: k must be an integer');
    }
    
    if (k < 1 || k > nums.length) {
        throw new Error('Window size k must be between 1 and nums.length');
    }
    
    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 of elements smaller than current element from the end
        while (deque.length > 0 && nums[deque[deque.length - 1]] <= nums[i]) {
            deque.pop();
        }
        
        // Add current index to deque
        deque.push(i);
        
        // If we've processed at least k elements, add the maximum to result
        if (i >= k - 1) {
            result.push(nums[deque[0]]);
        }
    }
    
    return result;
}
```