Problem of the Day
Tuesday, January 20, 2026
Problem:
Consider the following definitions, with integer values stored in a two-dimensional array.
int[][] arr2d = {{ 0, 1, 2, 3},
{ 4, 5, 6, 7},
{ 8, 9, 10, 11}};
int height = arr2d.length;
int width = arr2d[0].length;It's possible to represent these same row-column values in a single-dimensional array.
int[] arr1d = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int n = /* code not shown */;where a value at index n corresponds with a given value at the position row, col. Which of the following calculations can replace /* code not shown */ to calculate the index n whose value correctly corresponds with that from the two-dimensional array at position row, col?
n = row * height + coln = col * height + rown = col * width + rown = row * width + col
The correct answer is d. The value 6 for example, at row 1 and column 2, would have its index n calculated as n = row * width + col, or n = 1 * 4 + 2, which is 7, the index of that value in the one-dimensional array.