Diagonal Traverse (for E4 ;)
Updated
Problem statement
Given an m x n matrix mat, return all elements in diagonal order. Start at the top-left cell, traverse the first diagonal up-right, alternate direction on every following diagonal, and finish at the bottom-right cell.
Function
findDiagonalOrder(mat: int[][]) → int[]Examples
Example 1
mat = [[1,2,3],[4,5,6],[7,8,9]]return = [1,2,4,7,5,3,6,8,9]The diagonals are visited as [1], [2,4], [7,5,3], [6,8], and [9], with direction alternating each time.
Example 2
mat = [[1,2],[3,4]]return = [1,2,3,4]The diagonals are [1], [2,3], and [4], producing [1,2,3,4].
Constraints
m == mat.lengthn == mat[i].length1 <= m, n <= 10^41 <= m * n <= 10^4-10^5 <= mat[i][j] <= 10^5
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- 2D Convolution Layer Forward PassWaymo · PHONE SCREENWaymo interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Days Until Poisoned Plants StabilizeApple · PHONE SCREENApple interview questions
- Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
- Dense Matrix MultiplicationAmazon · PHONE SCREEN
- File-Backed Dense Game of LifeApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Tilting Maze BallHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
- Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
- Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences