```python
def zigzag(n, k):
    """
    Calculates the Entringer number e(n, k).

    Entringer numbers, e(n, k), are defined by the recurrence relation:
    e(0, 0) = 1
    e(n, 0) = 0 for n > 0
    e(n, k) = e(n, k-1) + e(n-1, n-k) for 1 <= k <= n.
    """
    if not (0 <= k <= n):
        return 0

    if n == 0:
        # This handles the case n=0, k=0, returning 1.
        return 1

    # A space-optimized dynamic programming approach is used.
    # We only need the previous row of the Entringer number triangle
    # to compute the current row.
    # 'prev_row' stores the values e(i-1, j) for the current iteration i.
    prev_row = [0] * (n + 1)
    prev_row[0] = 1  # Base case e(0, 0) = 1

    # Iterate to build the triangle row by row, from i = 1 to n.
    for i in range(1, n + 1):
        curr_row = [0] * (n + 1)
        # For each row i, calculate entries e(i, j) for j from 1 to i.
        for j in range(1, i + 1):
            # Apply the recurrence relation: e(i, j) = e(i, j-1) + e(i-1, i-j)
            curr_row[j] = curr_row[j - 1] + prev_row[i - j]
        
        # The newly computed row becomes the 'prev_row' for the next iteration.
        prev_row = curr_row

    return prev_row[k]
```