Company: Autodesk_10april
Difficulty: medium
Longest Diagonal Segment Problem Description You are given a rectangular matrix whose every element is 0 , 1 or 2 . Find the length of the longest diagonal segment of the matrix whose elements, read from its first element to its last, match the pattern 1, 2, 0, 2, 0, 2, 0, ... That is, the first element is 1 , and after it the values 2 and 0 alternate for as long as the segment continues. A diagonal segment: is a run of consecutive cells taken along one of the four diagonal directions (up-left, up-right, down-left, down-right), each cell being the diagonal neighbour of the previous one in that same direction; may start and end at any element of the matrix, but it must start at an element containing 1 ; has a length equal to the number of cells it contains. A single cell containing 1 is a valid segment of length 1 . (inferred - the source allows a segment to start and end at any element; the stored reference counts a lone 1 as length 1.) The pattern never restarts: after the first eleme