Leetcode 562

Y Tech
2 min readAug 28, 2023

Coding question asked in Google Interviews.

'''
If the grid[i][j] == 1, then:
horizontal: dp[i][j] = dp[i][j-1] + 1
vertical: dp[i][j] = dp[i-1][j] + 1
diag: dp[i][j] = dp[i-1][j-1] + 1
anti-diag: dp[i][j] = dp[i-1][j+1] + 1
'''
class Solution:
def longestLine(self, mat: List[List[int]]) -> int:
rows = len(mat)
cols =…

--

--