We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
while (true) {
if (mainControl + buffer > n + 1) {
break;
}
while (true) {
if (ik + buffer > n) {
ik = mainControl++;
jk = 0;
break;
}
int sum = 0;
for (int i = ik; i < ik + 3; i++) {
if (jk + buffer > n) {
jk = jk + 1;
ik++;
break;
}
for (int j = jk; j < jk + 3; j++) {
int iStartIndex = ik;
int jStartIndex = jk;
int i1 = a[i][j];
if (i == iStartIndex || i == iStartIndex + 2) {
sum = sum + i1;
} else if (i == iStartIndex + 1) {
iStartIndex++;
jStartIndex++;
if (iStartIndex == i && jStartIndex == j) {
sum = sum + a[i][j];
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Can u check this?
while (true) { if (mainControl + buffer > n + 1) { break; } while (true) { if (ik + buffer > n) { ik = mainControl++; jk = 0; break; } int sum = 0; for (int i = ik; i < ik + 3; i++) { if (jk + buffer > n) { jk = jk + 1; ik++; break; } for (int j = jk; j < jk + 3; j++) { int iStartIndex = ik; int jStartIndex = jk; int i1 = a[i][j]; if (i == iStartIndex || i == iStartIndex + 2) { sum = sum + i1; } else if (i == iStartIndex + 1) { iStartIndex++; jStartIndex++; if (iStartIndex == i && jStartIndex == j) { sum = sum + a[i][j]; } } } }