FastPrepTraverse Interior Matrix Cells in Row-Major Order
Problems/Traverse Interior Matrix Cells in Row-Major Order

Traverse Interior Matrix Cells in Row-Major Order

Citadel logoCitadel● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel intern onsite interview. The report names a walk through a two-dimensional matrix that skips the boundary rows and columns. It does not give the order of the walk, how the answer is returned, what to do at the edges, or the function interface. Our version returns the inner values in row-major order. It is about 70% the same as the reported question.

You are given a non-empty rectangular integer matrix matrix. Traverse its interior cells in row-major order and return their values.

A cell is on the boundary when it belongs to the first row, last row, first column, or last column. Interior cells belong to none of those boundary lines.

Visit interior rows from top to bottom and, within each row, visit interior columns from left to right. If the matrix has fewer than three rows or fewer than three columns, return an empty array.

Function

traverseInteriorCells(matrix: int[][]) → int[]

Examples

Example 1

matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]return = [6,7,10,11]
matrix
0123012341567829101112313141516

The interior cells are (1,1), (1,2), (2,1), and (2,2). Row-major traversal returns their values in that order.

Example 2

matrix = [[1,2,3],[4,5,6],[7,8,9]]return = [5]
matrix
012012314562789

A three-by-three matrix has exactly one interior cell, the center.

Example 3

matrix = [[1,2,3,4],[5,6,7,8]]return = []
matrix
01230123415678

With only two rows, every cell lies on the first or last row, so there are no interior cells.

Constraints

  • 1 <= matrix.length, matrix[0].length <= 1000.
  • matrix.length * matrix[0].length <= 10^6.
  • Every row has the same length.
  • -2^31 <= matrix[row][col] <= 2^31 - 1.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Limit Order Book Matching EnginePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Fixed-Capacity Circular BufferONSITE INTERVIEW · Seen Jun 2026
  • Stock Trading with a Fee and a CooldownONSITE INTERVIEW · Seen May 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Minesweeper Board UpdateUber · ONSITE INTERVIEWUber interview questions
  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Diagonal Matrix IteratorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • Citadel SWE Intern First-Round Questions: 20 Experiences

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] traverseInteriorCells(int[][] matrix) {
      // write your code here
    }
}
Checking account…