Palindrome pairs: Difference between revisions

Same wording appears on leetcode.
(Same wording appears on leetcode.)
 
(9 intermediate revisions by 4 users not shown)
Line 1:
Task deleted pending original task writer giving some indication that the same task on leetcode and here have no plagiarism issues.
Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome.
<br>
Input: ["abcd","dcba","lls","s","sssll"]
<br>
Output:
<br>
(abcd,dcba)
<br>
(dcba,abcd)
<br>
(s,lls)
<br>
(lls,sssll)
<br>
=={{header|Ring}}==
{{draft task}}
<lang ring>
# Project : Palindrome pairs
# Date : 2018/07/27
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
 
load "stdlib.ring"
pairs = ["abcd","dcba","lls","s","sssll"]
for n = 1 to len(pairs)-1
for m = n + 1 to len(pairs)
pal1 = pairs[n] + pairs[m]
pal2 = pairs[m] + pairs[n]
if palindrome(pal1)
see "(" + pairs[n] + "," + pairs[m] + ")" + nl
ok
if palindrome(pal2)
see "(" + pairs[m] + "," + pairs[n] + ")" + nl
ok
next
next
</lang>
Output:
<pre>
(abcd,dcba)
(dcba,abcd)
(s,lls)
(lls,sssll)
</pre>
Anonymous user