Company: Autodesk_10april
Difficulty: medium
Longest Diagonal Segment Problem Description Given a matrix of integers, with each element containing either 0, 1, or 2, your task is to find the longest diagonal segment which matches the following pattern: 1, 2, 0, 2, 0, ... (where the first element is 1, and then 2 and 0 are repeating infinitely). The diagonal segment: May start and end at any matrix element. May go toward any possible diagonal direction. Diagonal segments should start from an element containing 1. There are four elements containing 1 in this matrix, so four possible starting points for diagonal segments. Try starting from all of these elements one by one, and moving in all directions to find the longest possible diagonal segment which matches the specified pattern. Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(matrix.length * matrix[0].length³) will fit within the execution time limit. Examples Example 1: Input: matrix = [[0, 0, 1, 1], [2, 2, 2