Question bank › Backtracking
Dsa Backtracking Warm-up

Garden Path Paths

Given a garden represented as an m x n grid of cells, where '1' represents a flower and '0' represents an empty cell, you need to find all unique paths from the top-left corner (0,0) to the bottom-right corner (m-1,n-1) by only moving right or down, ensuring that you step on exactly K flowers along the way. Print all such paths in a specific format. Input Format: - The first line contains three integers, m, n, and K (1 ≤ m, n ≤ 10; 0 ≤ K ≤ m+n-2). - The next m lines each contain n space-separated integers (either 0 or 1) representing the garden grid. Output Format: - Print all unique paths as lists of coordinates (x,y) in sorted order. Each path should be in a new line, and the coordinates should be printed as (x,y). Example: Input: 3 3 2 1 0 0 1 1 0 0 1 1 Output: (0,0) (1,0) (1,1) (2,1) (2,2) (0,0) (1,0) (1,1) (2,2) (0,0) (1,1) (2,1) (2,2)

Key concepts

backtrackingrecursionpathfinding

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.