Demonstration of the Largest Square Submatrix
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;


Do you need &lt;iostream&gt;?



bool check_Same_Length(std::vector&lt; std::vector&lt;int&gt; &gt; maximalSquareInput)


Space in the typename isn't required since c++11.

Not thrilled with the naming.  The function could be better named to signal that you are checking the column counts.  The parameter doesn't have to be your maximal input, but any 2D container.

You copy the vector of vectors every time you call a function.  Pass your matrix by reference (and to const if immutable).

bool has_equal_column_counts(const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix)




    size_t length = maximalSquareInput[0].size();


size_t is missing its std:: namespace prefix.  Consider auto.

What happens if maximalSquareInput is empty?  If you are not going to check the preconditions yourself, you should at least document them.

    for (int i = 0; i &lt; maximalSquareInput.size(); ++i) {
        if (length == maximalSquareInput[i].size()) {
            state = true;
        } else {
            state = false;
            return state;
        }
    }
    return state;


When you are accessing elements by an index and you are not using any index arithmetic, consider using range-based for.

    for (const auto&amp; row : maximalSquareInput) {
        if (length == row.size()) {
            state = true;
        } else {
            state = false;
            return state;
        }
    }
    return state;


If you are returning false the first time you encounter an invalid length, just return false.

    for (const auto&amp; row : maximalSquareInput) {
        if (length != row.size()) {
            return false;
        }
    }
    return true;


It turns out, the standard library has two functions that will do what you want here. You could use std::find or std::all_of, but std::adjacent_find works as well.

    auto not_equal_size = [](const auto&amp; v1, const auto&amp; v2) { 
        return v1.size() != v2.size(); 
    };
    return matrix.end()
        == std::adjacent_find(maximalSquareInput.begin(), 
                              maximalSquareInput.end(),
                              not_equal_size)




bool only_1_And_0(std::vector&lt; std::vector&lt;int&gt; &gt; maximalSquareInput)


Function should be named all_are_one_or_zero.

    for (int i = 0; i &lt; maximalSquareInput.size(); ++i) {
        if (!(std::all_of(maximalSquareInput[i].begin(), maximalSquareInput[i].end(),
                          [] (int digit) { return digit == 1 || digit == 0; })))
        {
            return false;
        }
    }
    return true;


Again, range-based for would be better than index-based for.

Consider adding more tools to your toolbox to reduce repetition (DRY - Don't repeat yourself).  You have a couple functions iterating over collections of iterables.  An iterator that chains those collections (essentially "flattening" the collection) would allow you to simplify your function.  Consider the following code (exposition-only):

bool all_are_one_or_zero(const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix) {
    return std::all_of(make_flatten_iterator{matrix},
                       make_flatten_iterator{},
                       [](int digit) { return digit == 1 || digit == 0; });
}

auto find_biggest_element(const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix) {
    return std::max_element(make_flatten_iterator{matrix},
                            make_flatten_iterator{});
}




int findBiggestElement(std::vector&lt; std::vector&lt;int&gt; &gt; maximalSquareOutput)


Be consistent with your formatting/style.  You're function names have mixed snake_Camel_Case and camelCase.  Pick one, stick with it.

If this was meant to be a generalized max element finder for a matrix, you should consider (a) what happens if the matrix is empty, and (b) is 0 the minimum element value for type int?



std::string findLargestSubmatrix(const std::vector&lt; std::vector&lt;int&gt; &gt; maximalSquareInput)


Why return a string? Consider just returning either the square length or the square area and let the caller convert it to a string if they want it formatted.

You've used "Biggest" and "Largest" but you've always called the input parameter "maximal" (for maximum).  Just call it maximum and you can cut down on the parameter name.

std::size_t max_length_of_square_submatrix(const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix)




    if(check_Same_Length(maximalSquareInput) &amp;&amp; only_1_And_0(maximalSquareInput))


Back to being consistent, you have spaces to distinguish between language constructs (if, for) and functions and in this instance you don't.

Avoid unnecessary code nesting by returning early.

    if (!check_Same_Length(maximalSquareInput) || !only_1_And_0(maximalSquareInput)) 
    {
        return 0;
    }

    for (...)


Do you even need to check? Should that be the responsibility of some other function?



        for (int row = 0; row &lt; maximalSquareInput.size(); ++row)
        {
            for (int column = 0; column &lt; maximalSquareInput[row].size(); ++column)
            {
                if (row == 0 || column == 0 || maximalSquareInput[row][column] == 0)
                {


You check to see if you are on either the first row or first column.  When in either the first row or first column, you already know you can't make a square towards the northwest.  Therefore, you can just copy those values into your matrix of sums before calculating the entire matrix.  Then you check from [1,row][1,col].

std::size_t max_area_of_square_submatrix(const std::vector&lt;std::vector&lt;int&gt;&gt;&amp; matrix)
{
    auto sums = matrix;

    for (std::size_t row = 1; row &lt; matrix.size(); ++row)
    {
        for (std::size_t col = 1; col &lt; matrix.size(); ++col)
        {
            if (matrix[row][col]) {
                sum[row][col] = 1 + std::min({sum[row-1][col],
                                              sum[row][col-1],
                                              sum[row-1][col-1]});
            } 
            else 
            {
                sum[row][col] = 0;
            }
        }
    }
    auto max_length = find_maximum_element(sums);
    return max_length * max_length;
}

std::string MaximalSquare(std::string strArr)
{
    auto matrix = to_matrix2i(strArr);
    if (!has_equal_column_counts(matrix) ||
        !all_are_one_or_zero(matrix)) 
    {
        return "0";
    }
    return std::to_string(max_area_of_square_submatrix(matrix));
}