Question bank › Backtracking
Dsa Backtracking Medium

Coloring a Grid

You are given a grid of size n x n and a target color k. Your goal is to find all unique ways to color the grid such that no two adjacent cells (including diagonally adjacent) share the same color. The total number of colors available is k. Output the total number of unique colorings possible. Input: - The first line contains two integers n (1 <= n <= 10) and k (1 <= k <= 10). Output: - A single integer representing the number of unique colorings possible. Example: Input: 2 2 Output: 6

Key concepts

backtrackinggridcombinatorial

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.