Trains the technique from
LeetCode 827Making A Large IslandThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An orchard occupies a square plot laid out as the n x n grid field. A cell holds 1 where a tree already stands and 0 where the ground is still bare.
Two trees belong to the same stand when you can get from one to the other by stepping between trees that share a full side of their cells, moving up, down, left or right. Cells that merely touch at a corner are not linked. The size of a stand is the count of trees in it.
The grower may plant a tree on one bare cell, or may plant nothing at all. Return the size of the biggest stand the orchard can end up with after that single choice.
Example 1
Planting the bare cell in the top right corner joins the pair of trees along the top row with the pair down the right edge, giving a stand of five.
Example 2
Eight trees already ring a single bare cell in the middle, and planting it pulls the whole ring plus the new tree into one stand of nine.
Example 3
The three trees only touch at corners, so none of them are linked. The best single planting bridges two of them for a stand of three.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def largest_planted_block(field: list[list[int]]) -> int:public int largestPlantedBlock(int[][] field)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.