Palindrome Word Bridges Problem

Palindrome Word Bridges Problem — ExecCode Hard DSA Practice

Solve the Palindrome Word Bridges problem on ExecCode. Free online hard DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

You are given distinct words. Pair two different indices (i, j) if the concatenation words[i] + words[j] is a palindrome. Checking every pair with a full concatenate is too slow when words share prefixes. Return every valid index pair [i, j] (i != j). Sort pairs lexicographically by i then j. You are given: words — list of lowercase strings, all unique Return sorted list of [i, j] pairs. Order of concatenation is words[i] then words[j], not the reverse unless that reverse pair is also listed.

Examples

Input {'words': ['abcd', 'dcba', 'lls', 's', 'sssll']}; Output [[0, 1], [1, 0], [2, 4], [3, 2]]. Input {'words': ['bat', 'tab', 'cat']}; Output [[0, 1], [1, 0]]. Input {'words': ['a', '']}; Output [[0, 1], [1, 0]]

Constraints

Words may have different lengths Empty leftover after a split still counts (the other word itself must be palindrome)

Practice Palindrome Word Bridges free on ExecCode. Browse DSA problems, topic map, and placement guides.