Skip to content

Practice Maximum Trailing Zeros in a Cornered Path

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2245
LeetCode Problem

Maximum Trailing Zeros in a Cornered Path

Problem Statement

You are given a 2D integer array grid of size m x n, where each cell contains a positive integer. A cornered path is defined as a set of adjacent cells with at most one turn. More specifically, the path should exclusively move either horizontally or vertically up to the turn (if there is one), without returning to a previously visited cell. After the turn, the path will then move exclusively in the alternate direction: move vertically if it moved horizontally, and vice versa, also without returning to a previously visited cell. The product of a path is defined as the product of all the values in the path. Return the maximum number of trailing zeros in the product of a cornered path found in grid.

Source: Maximum Trailing Zeros in a Cornered Path on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[23,17,15,3,20],[8,1,20,27,11],[9,4,6,2,21],[40,9,1,10,6],[22,7,4,5,3]]
Output
3

# Example 2

Input
grid = [[4,3,2],[7,6,1],[8,8,8]]
Output
0

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 10^5
1 <= m * n <= 10^5
1 <= grid[i][j] <= 1000

Related LeetCode Problems

Practice more problems similar to Maximum Trailing Zeros in a Cornered Path.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.