Description
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:
Input: s = "leetcode"
Output: true
Explanation: Substring "ee" is of length 2 which is also present in reverse(s) == "edocteel".
Example 2:
Input: s = "abcba"
Output: true
Explanation: All of the substrings of length 2 "ab", "bc", "cb", "ba" are also present in reverse(s) == "abcba".
Example 3:
Input: s = "abcd"
Output: false
Explanation: There is no substring of length 2 in s, which is also present in the reverse of s.
Β
Constraints:
1 <= s.length <= 100sconsists only of lowercase English letters.
Solution
Python3
class Solution:
    def isSubstringPresent(self, s: str) -> bool:
        N = len(s)
        r = s[::-1]
        
        for i in range(N - 1):
            if s[i : i + 2] in r:
                return True
        
        return False