X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Perfect Reversible String
Basic Accuracy: 77.73% Submissions: 488 Points: 1

You are given a string ‘str’, the task is to check that reverses of all possible substrings of ‘str’ are present in ‘str’. If yes then the answer is 1, otherwise, the answer will be 0.

Example 1:

Input: n = 2, str = "ab"
Output: 0
Explanation: All substrings are "a",
"b","ab" but reverse of "ab" is not 
present in str.

​Example 2:

Input: n = 3, str = "aba"
Output: 1
Explanation: Reverse of all possible 
substring is present in str.

Your Task:  
You don't need to read input or print anything. Your task is to complete the function isReversible​() which takes the string str and n (the length of str) as inputs and returns the answer.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ n ≤ 2 * 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Perfect Reversible String

Output Window