Trains the technique from
LeetCode 336Palindrome PairsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Labels are given as labels, each a string of lowercase letters. A label may be empty, and two labels may read alike while sitting at different positions in the list.
Return every ordered pair of positions [i, j] with i and j different, such that the label at i written straight before the label at j, with nothing between them, reads the same backwards as forwards.
List the pairs in increasing order, comparing the first position and, where those match, the second.
Example 1
Either way round the two labels join into a four-letter string that reads the same backwards, so both orderings count.
Example 2
Six joins work. Position 0 goes before positions 1 and 2, position 1 goes before position 0, position 2 goes before position 3, and position 3 goes before positions 1 and 2. Position 0 before position 3 fails: that join runs to seven letters and its two ends do not answer each other.
Example 3
Neither ordering of the two labels reads the same backwards, so nothing is reported.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def palindrome_pairs(labels: list[str]) -> list[list[int]]:public List<List<Integer>> palindromePairs(String[] labels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.