Question bank › Trie
Dsa Trie Hard

Suffix-Prefix Linker

Given two sets of words, A and B, find the length of the longest string S such that S is a suffix of at least one word in set A AND S is a prefix of at least one word in set B. Input Format: 1. Integer N (size of set A), followed by N words. 2. Integer M (size of set B), followed by M words. Output Format: Integer representing the maximum length of S. Example: Input: 2 apple banana 2 leash nasal Output: 2 Explanation: 'le' is a suffix of 'apple' and a prefix of 'leash'. 'na' is a suffix of 'banana' and a prefix of 'nasal'. Both have length 2.

Key concepts

suffix-matchingtrie-optimization

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.