Diagonal Bounce Traversal
Updated
Problem statement
You are given an integer matrix matrix. Return the values visited by a diagonal path.
For this exercise, assume the path starts at the top-left cell and initially moves down and right. Each step advances one column. Before a step would leave the top or bottom edge, reverse the vertical direction. Stop after visiting the last column.
For a matrix with one row, stay on that row. Return the visited values in order, including the starting cell. The matrix is not changed.
Function
diagonalBounce(matrix: int[][]) → int[]Examples
Example 1
matrix = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]return = [1,7,13,9,5]The visited cells are (0,0), (1,1), (2,2), (1,3), and (0,4). Their values are [1,7,13,9,5].
Example 2
matrix = [[9,8,7]]return = [9,8,7]There is one row, so the path visits its three values from left to right.
Constraints
- 1 <= matrix.length <= 100
- 1 <= matrix[r].length <= 1000
- -10^6 <= matrix[r][c] <= 10^6
- All rows have the same length.
More Autodesk interview questions
Similar questions at other companies
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Costliest ChocolateRippling · OARippling interview questions
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Plus Mult ArrayIBM · OAIBM interview questions
- Progressive Tax CalculatorInteractive Brokers · OA
- 2020 Account Balance with Monthly Card FeesDRW · OADRW interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- First Fibonacci Number at Least the Array SumBitGo · OABitGo interview questions
- Metro Fare With a Daily CapMicrosoft · OAMicrosoft interview questions