Question bank › Two Pointers
Dsa Two Pointers Easy

Sticky DNA Match

You are analyzing two DNA strands, A and B. A 'sticky match' occurs when a prefix of strand A, when reversed, exactly matches a suffix of strand B. Given two strings, find the length of the longest such sticky match. Example: Input: ALPHABET TEBA Output: 3 Explanation: The prefix of A 'ALP' reversed is 'PLA' (no). The prefix 'A' reversed is 'A' (suffix of B). The prefix 'ALB' (no). Wait: 'ALPH' is prefix, B suffix 'TEBA'... The prefix 'ABE' reversed is 'EBA', which is a suffix of 'TEBA'. The longest prefix of A that matches the reversed suffix of B is 'ABE' (length 3). Worked Example: A = 'GATTACA', B = 'ACATTAG' Prefixes of A: 'G', 'GA', 'GAT', 'GATT', 'GATTA', 'GATTAC'... Suffixes of B: 'G', 'AG', 'TAG', 'TTAG', 'ATTAG', 'CATTAG'... 'GATTAC' reversed is 'CATTAG'. Length 6. Input Format: Two lines, each containing a string. Output Format: A single integer representing the maximum length.

Key concepts

two_pointersstring_manipulation

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.