Dsa
Backtracking
Medium
Word Tower Construction
You are given a list of N unique words. A 'Word Tower' is a sequence of K words from the list where each word (except the first) must begin with the last two letters of the previous word. Each word in the tower must be unique. Calculate the total number of unique Word Towers of length exactly K that can be built.
Input:
First line: K and N.
Following N lines: One word per line.
Output: Total number of valid sequences.
Example:
Input:
3 4
apple
lemon
onion
only
Output: 1
Explanation: The only sequence of length 3 is apple -> lemon -> onion (le-le, on-on).
Key concepts
backtrackingstringspermutations
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