Word Pairs That Make a Mirror
All strings in words are different. Return every pair of positions [i, j] with i != j for which words[i] + words[j] reads the same from both ends. The pairs can come in any order.
The order inside a pair matters: [i, j] and [j, i] are two pairs, and each is listed only if its own joined string reads the same from both ends.
Example 1
words ["ab","cba","a",""]
returns [[0,1],[0,2],[2,3],[3,2]]
The joined strings are abcba, aba, and a twice: the empty string pairs with a on either side.
Example 2
words ["one","two"]
returns []
Neither onetwo nor twoone reads the same from both ends.
Constraints
1 <= len(words) <= 400 <= len(words[i]) <= 8- the words hold lowercase letters and are all different
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Hash maps problems
- Words Glued TogetherHard
- Already Seen FlagsBeginner
- Best Score per NameBeginner
- Check if the Sentence Is PangramBeginner
- Count Elements With a NextBeginner
- Difference of Two ArraysBeginner
- First Repeated WordBeginner
- Is IsogramBeginner