Existence of a Substring in a String and Its Reverse - Problem
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.
Note: A substring is a contiguous sequence of characters within a string.
Input & Output
Example 1 — Basic Case
$
Input:
s = "abcba"
›
Output:
true
💡 Note:
The 2-character substring "ab" appears at the beginning of the original string and also appears at the beginning of the reversed string "abcba"
Example 2 — No Match
$
Input:
s = "abcd"
›
Output:
false
💡 Note:
Original string has substrings "ab", "bc", "cd". Reversed string "dcba" has substrings "dc", "cb", "ba". No common 2-character substring exists.
Example 3 — Single Match
$
Input:
s = "leetcode"
›
Output:
true
💡 Note:
The substring "ee" appears in the original string. The reversed string "edocteel" also contains "ee", so return true.
Constraints
- 1 ≤ s.length ≤ 100
- s consists of lowercase English letters only
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code