Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

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 * 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login 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?

YesLoading...

Perfect Reversible String

...