Question bank › Backtracking
Dsa Backtracking Medium

Garden Path

You have a garden with a dimension of n rows and m columns represented as a grid. You want to plant flowers in a way that no two adjacent cells contain flowers. Write a program that determines all possible ways to plant flowers using exactly k flowers. Each cell can either be empty or contain one flower, and flowers cannot be planted in directly adjacent cells (horizontally or vertically). The program should return the total number of unique configurations. Input format: - The first line contains three integers n (1 ≤ n ≤ 10), m (1 ≤ m ≤ 10), and k (0 ≤ k ≤ n * m). Output format: - A single integer representing the total number of unique configurations. Example: Input: 2 2 2 Output: 1 In this example, the only configuration is to put flowers in opposite corners of the 2x2 grid.

Key concepts

backtrackingcombinatoricssearch

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.