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.
int strangeGrid(int r, int c) {
// Base value for the row group (each pair of rows increases base by 10)
int base = (r - 1) / 2 * 10;
// Check if the row is odd or even
if (r % 2 == 1) {
// Odd row: Start at base, increment by 2 for each column
return base + (c - 1) * 2;
} else {
// Even row: Start at base + 1, increment by 2 for each column
return base + 1 + (c - 1) * 2;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strange Grid Again
You are viewing a single comment's thread. Return to all comments →
int strangeGrid(int r, int c) { // Base value for the row group (each pair of rows increases base by 10) int base = (r - 1) / 2 * 10;
}