Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopgrid · connected-components · geometry
The organizer’s problem statement is available at the official source link.
component perimeter
Fence only the exposed sides of potato patches
Four-neighbor connected potato fields form patches. Count exposed sides for each patch and report the largest perimeter.
| . | P | . |
| P | P | . |
| . | P | . |
- 1
Find each patch
Flood-fill cultivated fields using shared-edge adjacency. - 2
Count exposed sides
A side contributes when its neighbor is uncultivated or outside the farm. - 3
Keep the largest perimeter
Sum exposed sides per patch and report the maximum, not the total over all patches.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.