# Incorrect judgement on interviewbit

#1

My code is working on my computer but not on interviewbit, look at this case:

``````int Solution::solve(vector<string> &a) {
bool rf = false, gf = false, bf = false;

for (auto e : a) {
for (auto c : e) {
if (c == 'r') rf = true;
if (c == 'g') gf = true;
if (c == 'b') bf = true;
}
}

if (!rf || !gf || !bf) {
return 0;
}

int n = a.size();
if (n <= 1) {
return 0;
}
int m = a[0].size();
//cout << "m: " << m << "????\n";

vector<vector<int>> col(m, vector<int>(3, 0));

for (int i = 0; i < m; ++i) {
int rf = 0, gf = 0, bf = 0;
for (int j = 0; j < n; ++j) {
if (a[j][i] == 'r') rf = 1;
if (a[j][i] == 'g') gf = 1;
if (a[j][i] == 'b') bf = 1;
}
col[i] = {rf, gf, bf};
}

int ans = 0;
string choice[3] = {"rgb", "gbr", "brg"};
map<char, int> mp({{'r', 0}, {'g', 1}, {'b', 2}});

for (int i = 0; i < 3; ++i) {
char ot = choice[i][2];
char c1 = choice[i][0], c2 = choice[i][1];

for (int j = 0; j < m; ++j) {
int len = 0, ht = 0;

if (col[j][mp[c1]] && col[j][mp[c2]]) {
int p1f = -1, p1l, p2f = -1, p2l;

for (int k = 0; k < n; ++k) {
if (a[k][j] == c1) {
if (p1f == -1) {
p1f = k;
}
p1l = k;
}
else if (a[k][j] == c2) {
if (p2f == -1) {
p2f = k;
}
p2l = k;
}
}
len = max({abs(p1f-p2f), abs(p1f-p2l), abs(p1l - p2f), abs(p1l-p2l)});

int of = -1, ol;
for (int k = 0; k < m; ++k) {
if (col[j][mp[ot]]) {
if (of == -1) {
of = k;
}
ol = k;
}
}
ht = max(abs(of-j), abs(ol-j));
//cout << ht << " " << len << "? ";
ans = max(ans, ht*len + ht + len + 1);
//cout << ot << " " << j << "?\n";
}

}
}
return (ans+1)/2;

}
``````

Look at this case;

16
rbbbggrbrbrggrgr bgbrbbrgggrgrrrr rgbrrrbbgbbbrrrb bbgbrgrbbrgrrgbb ggbrbrrbggggrrgb bgbrbrggbgrrgbrg grbbbgrbgbbgbbgr rbgbgbrrgrgbgbbr gbgrrgbbrrbbgbbg brgrbbrrbrgbgbrb rbbrrrbgrbgrbbrg rrggrrbbbrgbgggg rrrrgbbrgbbgbbrg rgbgrrrrggbbrrgr ggbrbbbbgrrrbrbb gggggrgbrbrbrrgr

My code correctly gives 128 but the interviewbit shows 120 as correct answer. But following given sample, answer must be 128 As there is upper left corner is r, lower left is g, and there is b in rightmost. So we will get (16*16)/2 following the given example, and we get 128.

#2

If you guys have any doubt about testcases or soln check this out…it will surely help you