A heat-map dashboard has n regions numbered 0 to n - 1. borders lists pairs [a, b] of regions that touch. The designer has colors colors and wants touching regions to have different colors.
Write countColorings(n, borders, colors) that returns how many ways there are to give every region one color so that no two touching regions share a color. Colorings that differ in at least one region count as different.
Input: n = 3, borders = [[0,1],[1,2]], colors = 2 Output: 2
In a chain of 3 regions with 2 colors, the colors must alternate, and either color can start.
Input: n = 3, borders = [[0,1],[1,2],[0,2]], colors = 2 Output: 0
Three regions that all touch each other need 3 different colors.
1 <= n <= 80 <= borders.length <= 281 <= colors <= 4Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #310 Color the Dashboard Regions. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.