FastPrepDiagonal Traverse
Problems/Diagonal Traverse

Diagonal Traverse

SambaNova Systems logoSambaNova Systems● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: A firsthand SambaNova phone interview report dated November 23, 2020 clearly describes the well-known Diagonal Traverse problem.

Given a non-empty rectangular integer matrix matrix, return all of its elements in diagonal order.

Number diagonals by row + column, starting with diagonal 0 at the top-left cell. Traverse even-numbered diagonals upward and to the right. Traverse odd-numbered diagonals downward and to the left. Continue until every matrix element has been returned exactly once.

Function

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

Examples

Example 1

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

The diagonals are visited as [1], [2,4], [7,5,3], [6,8], and [9].

Example 2

matrix = [[1,2,3],[4,5,6]]return = [1,2,4,5,3,6]
matrix
01201231456

The traversal alternates direction across the four diagonals of the rectangular matrix.

More SambaNova Systems Phone Screen questions

  • Deterministic Zigzag SortPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Minimum Window SubstringPHONE SCREEN · Seen Jun 2022
  • Number of ProvincesPHONE SCREEN · Seen Jun 2022
  • Merge Three Sorted ArraysPHONE SCREEN · Seen Jun 2022
  • Task Scheduler with CooldownPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Point Inside a TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Parse Variable, Expression, and Application TreesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Decode StringPHONE SCREEN · Seen Mar 2022
  • Insert, Delete, and Get Random in Constant TimePHONE SCREEN · Seen Mar 2022
  • Ugly NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2021

Similar questions at other companies

  • Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
  • Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Longest Consecutive Same-Color LineGoogle · PHONE SCREENGoogle interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Diagonal TraverseHive · PHONE SCREENHive interview questions
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREENNVIDIA interview questions
  • Multi-Channel Valid ConvolutionTesla · PHONE SCREENTesla interview questions
All SambaNova Systems interview questionsSee SambaNova Systems hiring insights
Saved
class Solution {
    public int[] findDiagonalOrder(int[][] matrix) {
        // write your code here
    }
}
Checking account…