FastPrepDiagonal Traverse
Problems/Diagonal Traverse

Diagonal Traverse

Hive logoHive● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: Reported in a Hive phone screen. The report names the well-known diagonal traversal task but gives no runnable function or examples. Our version is about 98% the same as the reported question.

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 Hive Phone Screen questions

  • Validate a Directed Edge AdditionPHONE SCREEN · Seen Jul 2026

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
  • Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREENCitadel interview questions
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREENNVIDIA interview questions
  • Multi-Channel Valid ConvolutionTesla · PHONE SCREENTesla interview questions
All Hive interview questionsSee Hive hiring insights
Saved
class Solution {
    public int[] findDiagonalOrder(int[][] matrix) {
        // write your code here
    }
}
Checking account…