Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Painting a Grid With Three Different Colors
Bookmark
Backtracking
Column-State DP
Matrix Power
Input
Example 1 (ans=3)
Example 2 (ans=6)
Example 3 (ans=54)
Example 4 (ans=54)
Custom
m
=
2
,
n
=
3
no two neighbours may share a colour
count = -
answer = -
no two neighbours may share a colour
count = -
answer = -
no two neighbours may share a colour
R
G
R
G
R
undo [1][2], 2 way(s) so far
count = -
answer = -
no two neighbours may share a colour
R
G
G
B
undo [0][2], 1 way(s) so far
count = 1
answer = -
no two neighbours may share a colour
R
B
R
G
R
try R at [1][2]
count = 6
answer = -
no two neighbours may share a colour
R
B
[1][0] = B
count = 9
answer = -
no two neighbours may share a colour
R
G
B
B
R
G
[1][2] = G
count = 2
answer = -
no two neighbours may share a colour
R
B
R
B
R
[1][2] contributes 2 way(s)
count = 2
answer = -
no two neighbours may share a colour
R
B
B
G
try G at [0][2]
count = 1
answer = -
no two neighbours may share a colour
G
R
R
[0][1] = R
count = 18
answer = -
no two neighbours may share a colour
54 valid colouring(s)
count = -
answer = 54
algo
master
.
io
Step:
Colour every cell of a 2x3 grid with 3 colours so no two neighbours match
0 / 322
Input
Example 1 (ans=3)
Example 2 (ans=6)
Example 3 (ans=54)
Example 4 (ans=54)
Custom
m
=
2
,
n
=
3
0 / 322
algo
master
.
io
Step:
Colour every cell of a 2x3 grid with 3 colours so no two neighbours match