# Problem Description
This is a matrix growth problem where:
- We have a 2D binary matrix (containing 0s and 1s)
- The growth process starts from the 1st row
- For each column, we need to calculate its final height after the growth process
- Height is defined as the number of continuous 1s starting from row 1
- The growth appears to follow specific rules of propagation upward
- We need to calculate the height for a specific column (given by input parameter)

# Visual Facts
1. Matrix Properties:
   - Both examples use binary matrices (0s and 1s)
   - Example 1: 7×6 matrix
   - Example 2: 6×8 matrix
   - Row numbering starts from bottom (1st row) to top (last row)
   - Column numbering starts from left (1) to right

2. Growth Process:
   - Orange colored cells show the growth pattern
   - Growth starts from row 1
   - Growth only occurs in vertical direction (upward)
   - Final heights are shown in the result table (H column)

3. Result Table Format:
   - Shows column number and corresponding height
   - Heights vary for different columns
   - Maximum height in Example 1 is 5 (column 4)
   - Maximum height in Example 2 is 5 (column 4)

# Visual Patterns
1. Growth Rules:
   - Growth only occurs if there's a continuous path of 1s from 1st row
   - A cell grows (becomes orange) if:
     * It contains 1
     * It's connected to a grown cell below it

2. Height Calculation:
   - Height is the count of continuous 1s from 1st row
   - Height stops counting when it hits first 0 or matrix boundary
   - In Example 1, column 4 has height 5 because it has 5 continuous 1s from the 1st row
   - Growth process doesn't change the original matrix values, only helps visualize the connectivity

3. Connectivity Pattern:
   - Only vertically connected 1s contribute to height
   - Any 0 in the path breaks the height count
   - Height is always counted from 1st row upward
   - Isolated 1s above a 0 don't contribute to height


# Solution
from typing import List

def solution(matrix: List[List[int]], col: int) -> int:
    """
    Calculates the final height of a specified column after a growth process in a 2D matrix.

    Args:
        matrix: A 2D list of integers representing the matrix
        col: 1-based index of the target column

    Returns:
        The final height of the specified column
    """
    j = col -1
    i = 0
    count = 0
    while i<=len(matrix):
        if matrix[i][j] == 1:
            count += 1
        else:
            break
        i += 1
    return count


# Test Script

def test():
    test_cases = [
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],1,2),
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],2,1),
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],3,1),
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],4,5),
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],5,1),
        ([
            [0, 0, 0, 1, 0, 1],
            [0, 0, 0, 0, 1, 1],
            [0, 0, 0, 1, 0, 1],
            [0, 1, 0, 1, 0, 1],
            [0, 1, 1, 1, 1, 0],
            [1, 0, 0, 1, 0, 1],
            [1, 1, 1, 1, 1, 1]
        ],6,2),
        ([
            [0, 0, 0, 0],
            [0, 0, 0, 1],
            [0, 1, 0, 1],
            [0, 1, 1, 1],
            [1, 0, 0, 1],
            [1, 0, 1, 1]
        ],1,2),
        ([
            [0, 0, 0, 0],
            [0, 0, 0, 1],
            [0, 1, 0, 1],
            [0, 1, 1, 1],
            [1, 0, 0, 1],
            [1, 0, 1, 1]
        ],2,0),
        ([
            [0, 0, 0, 0],
            [0, 0, 0, 1],
            [0, 1, 0, 1],
            [0, 1, 1, 1],
            [1, 0, 0, 1],
            [1, 0, 1, 1]
        ],3,1),
        ([
            [0, 0, 0, 0],
            [0, 0, 0, 1],
            [0, 1, 0, 1],
            [0, 1, 1, 1],
            [1, 0, 0, 1],
            [1, 0, 1, 1]
        ],4,5),
    ]

    for matrix, col, expected_output in test_cases:
        try:
            # Note: matrix is reversed before passing to solution
            output = solution(matrix[::-1], col)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`matrix`: \n"
                f"{'\n'.join(str(row) for row in matrix)}\n"
                f"`col`: {col}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`matrix`: \n"
                f"{'\n'.join(str(row) for row in matrix)}\n"
                f"`col`: {col}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()