Skip to content

Practice Find the Maximum Number of Fruits Collected

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

Hard#3363
LeetCode Problem

Find the Maximum Number of Fruits Collected

Problem Statement

Three children start in an n by n fruit grid at (0, 0), (0, n - 1), and (n - 1, 0). Each makes exactly n - 1 moves to (n - 1, n - 1), staying inside the grid. From (r, c), the first child may move to (r + 1, c), (r, c + 1), or (r + 1, c + 1); the second to (r + 1, c - 1), (r + 1, c), or (r + 1, c + 1); and the third to (r - 1, c + 1), (r, c + 1), or (r + 1, c + 1). Visiting a room collects its fruits, but a room’s fruits count only once even if several children visit it. Return the maximum total collected.

Source: Find the Maximum Number of Fruits Collected on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
fruits = [[1,2,3,4],[5,6,8,7],[9,10,11,12],[13,14,15,16]]
Output
100

# Example 2

Input
fruits = [[1,1],[1,1]]
Output
4

Constraints

2 <= n == fruits.length == fruits[i].length <= 1000
0 <= fruits[i][j] <= 1000

Related LeetCode Problems

Practice more problems similar to Find the Maximum Number of Fruits Collected.

Review your practice with PhantomCodeAI

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