Practice Count Fertile Pyramids in a Land
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
grid contains fertile cells 1 and barren cells 0; locations outside it are barren. A downward pyramid of height h >= 2 and apex (r,c) contains every cell (r+d,c+e) with 0 <= d < h and -d <= e <= d. An upward pyramid uses (r-d,c+e) instead. Count every such fully fertile plot of either orientation and return the total.
Source: Count Fertile Pyramids in a Land on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[0,1,1,0],[1,1,1,1]]
2
# Example 2
grid = [[1,1,1],[1,1,1]]
2
# Example 3
grid = [[1,1,1,1,0],[1,1,1,1,1],[1,1,1,1,1],[0,1,0,0,1]]
13
Constraints
Related LeetCode Problems
Practice more problems similar to Count Fertile Pyramids in a Land.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.