Copied to Clipboard
Palindrome Pairs
Hard Accuracy: 46.07% Submissions: 9544 Points: 8

Given an array of strings arr[] of size N, find if there exists 2 strings arr[i] and arr[j] such that arr[i]+arr[j] is a palindrome i.e the concatenation of string arr[i] and arr[j] results into a palindrome.

Example 1:

N = 6
arr[] = {"geekf", "geeks", "or","keeg", "abc", 
Output: 1 
Explanation: There is a pair "geekf"
and "keeg".

Example 2:

N = 5
arr[] = {"abc", "xyxcba", "geekst", "or", "bc"}
Output: 1
Explanation: There is a pair "abc"
and "xyxcba".

Your Task:  
You don't need to read input or print anything. Your task is to complete the function palindromepair() which takes the array arr[], its size N and returns true if palindrome pair exists and returns false otherwise.
The driver code itself prints 1 if returned value is true and prints 0 if returned value is false.


Expected Time Complexity: O(N*l2) where l = length of longest string in arr[]
Expected Auxiliary Space: O(N*l2) where l = length of longest string in arr[]


1 ≤ N ≤ 2*104

1 ≤ |arr[i]| ≤ 10

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Palindrome Pairs

Output Window