## Google Interview Question for Software Engineers

Country: United States

Comment hidden because of low score. Click to expand.
0
of 0 vote

O(m * n) time.

The follow up question is similar to the CareerCup site question having id=5121790555717632 (would be cool to allow links to the website itself).

``````#include <iostream>
#include <vector>

using namespace std;

bool Valid(vector<vector<char>> const &m)
{
for (int r = 0; r < m.size(); ++r) {
for (int c = 0; c < m[r].size(); ++c) {
int dups = 0;

if (r > 0 &&
m[r - 1][c] == m[r][c])
{
++dups;
}
if (r > 1 &&
m[r - 2][c] == m[r][c])
{
++dups;
}
if (dups > 1) {
return false;
}

dups = 0;

if (c > 0 &&
m[r][c - 1] == m[r][c])
{
++dups;
}
if (c > 1 &&
m[r][c - 2] == m[r][c])
{
++dups;
}
if (dups > 1) {
return false;
}
}
}
return true;
}

int main()
{
vector<vector<char>> m = {
{'R', 'G', 'R', 'B'},
{'R', 'Y', 'G', 'R'},
{'G', 'B', 'Y', 'Y'},
{'Y', 'G', 'B', 'G'},
{'B', 'R', 'Y', 'B'},
};
cout << Valid(m) << "\n";
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````bool IsValidMatrix(vector<vector<char>> const& data)
{
for (size_t row = 0; row < data.size(); row++)
for (size_t col = 0; col < data[row].size(); col++) {
if (row <= (data.size() - 3) && data[row][col] == data[row + 1][col] && data[row][col] == data[row + 2][col])
return false;
if (col <= (data[row].size() - 3) && data[row][col] == data[row][col + 1] && data[row][col] == data[row][col + 2])
return false;
}
return true;
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.