Existence of a Substring in a String and Its Reverse

Given a string s, find any substring of length 2 which is also present in the reverse of s.

Return true if such a substring exists, and false otherwise.

Example 1
Inputs = "leetcode"
Outputtrue
Substring "ee" is of length 2 and is also present in reverse(s) == "edocteel".
Example 2
Inputs = "abcba"
Outputtrue
All of the substrings of length 2, "ab", "bc", "cb", and "ba", are also present in reverse(s) == "abcba".

Constraints

  • 1 <= s.length <= 100
  • s consists only of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate