# 09. Predict the Column

The problem can be found at the following link: [Question Link](https://www.geeksforgeeks.org/problems/predict-the-column/1)

![](https://badgen.net/badge/Level/Easy/green)

## My Approach

I'll find and return the column index with the maximum number of zeros.

* To do this, I'll iterate through each column, counting the number of zeros in each column, and keeping track of the column with the maximum zeros.

## Time and Auxiliary Space Complexity

* **Time Complexity**: `O(n^2)` because we iterate through all elements in the `n x n` matrix.
* **Auxiliary Space Complexity**: `O(1)` as we use a constant amount of additional space.

## Code (C++)

```cpp
class Solution {
public:
    int columnWithMaxZeros(vector<vector<int>> &arr, int n) {
        int maxZeros = 0;
        int columnIdx = -1;
        
        for (int j = 0; j < n; j++) {
            int zerosCount = 0;
            for (int i = 0; i < n; i++) {
                if (arr[i][j] == 0) {
                    zerosCount++;
                }
            }
            
            if (zerosCount > maxZeros) {
                maxZeros = zerosCount;
                columnIdx = j;
            }
        }
        
        return columnIdx;
    }
};
```

## Contribution and Support

For discussions, questions, or doubts related to this solution, please visit our [discussion section](https://github.com/getlost01/gfg-potd/discussions). We welcome your input and aim to foster a collaborative learning environment.

If you find this solution helpful, consider supporting us by giving a ⭐ star to the [getlost01/gfg-potd](https://github.com/getlost01/gfg-potd) repository.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gl01.gitbook.io/gfg-editorials/2023/11-2023-nov-8/09-predict-the-column.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
