Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Making A Large Island
Bookmark
Input
2x2 Diagonal
Two Islands
Three Islands
All Land
All Water
Custom
grid
=
[[1,0],[0,1]]
1
0
0
1
1
0
0
1
phase:
label islands
1
0
0
1
phase:
label islands
2
0
0
1
island 2
has 1 cell
#2 ×1
phase:
label islands
2
0
0
1
#2 ×1
phase:
label islands
2
0
0
3
island 3
has 1 cell
#2 ×1
#3 ×1
phase:
try each 0
best =
0
2
0
0
3
for each
0
: 1 + Σ distinct island sizes
#2 ×1
#3 ×1
phase:
try each 0
best =
0
2
?
0
3
flip (0, 1)
: which islands touch it?
#2 ×1
#3 ×1
phase:
try each 0
best =
3
2
3
0
3
new best:
3
#2 ×1
#3 ×1
phase:
try each 0
best =
3
2
3
?
3
1
+
1
+
1
=
3
#2 ×1
#3 ×1
phase:
answer
2
3
0
3
return 3
algo
master
.
io
Step:
Making a Large Island: flip one 0 to 1 to build the biggest possible island
0 / 17
Input
2x2 Diagonal
Two Islands
Three Islands
All Land
All Water
Custom
grid
=
[[1,0],[0,1]]
0 / 17
algo
master
.
io
Step:
Making a Large Island: flip one 0 to 1 to build the biggest possible island