Question bank › Backtracking
Dsa Backtracking Medium

The Artisan's Loom

An artisan is weaving a pattern using three colors of thread: Red (R), Lily (L), and Tulip (T). The weaver must use an exact count of each thread: R, L, and T. However, there are strict aesthetic rules: 1) No two Lily (L) threads can be adjacent. 2) No three threads of the same color can ever appear consecutively. Write a program to calculate the total number of unique valid sequences. Input: Three space-separated integers R, L, and T representing the required count of each color. Output: A single integer representing the number of valid sequences. Example: Input: 1 1 1 Output: 6 Explanation: All permutations (RLT, RTL, LTR, LRT, TRL, TLR) are valid because no Ls are adjacent and no three colors repeat.

Key concepts

backtrackingmemoizationcombinatorics

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.