Longest Diagonal Pattern

Asked at Uber · Coding & Leetcode-style Questions · Difficulty: Medium

Given a 2D matrix containing integers 1, 2, and 0, find the length of the longest diagonal pattern in the matrix. The pattern starts with 1 and then alternates between 2 and 0. The diagonal can be either from top-left to bottom-right or bottom-left to top-right, without changing direction. Output the length of the longest pattern that meets these criteria.

Loading the problem…