Practice Length of Longest V-Shaped Diagonal Segment
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Length of Longest V-Shaped Diagonal Segment
Problem Statement
Given grid with values 0, 1, and 2, a valid diagonal segment starts with 1 and then follows 2, 0, 2, 0, and so on. It begins in any of the four diagonal directions and may make at most one clockwise 90-degree turn to another diagonal direction, continuing the same value sequence. Return the longest valid segment length, or 0 when no segment exists.
Source: Length of Longest V-Shaped Diagonal Segment on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[2,2,1,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]
5
# Example 2
grid = [[2,2,2,2,2],[2,0,2,2,0],[2,0,1,1,0],[1,0,2,2,2],[2,0,0,2,2]]
4
# Example 3
grid = [[1,2,2,2,2],[2,2,2,2,0],[2,0,0,0,0],[0,0,2,2,2],[2,0,0,2,0]]
5
# Example 4
grid = [[1]]
1
Constraints
Related LeetCode Problems
Practice more problems similar to Length of Longest V-Shaped Diagonal Segment.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.