FastPrepFastPrep
Problem Brief

Find Palindrome Sub-string

FULLTIMEOA
See Cisco online assessment and hiring insights

Ray likes puzzles. One day, he challenged Ansh with a puzzle to find a string that is the same when read forwards and backwards.

Write an algorithm to find the sub-string from the given string that is the same when read forwards and backwards.

Input

The input consists of a string - inputStr, representing the given string for the puzzle.

Output

From the given string, print a sub-string which is the same when read forwards and backwards.

Note

  • If there are multiple sub-strings of equal length, choose the lexicographically smallest one.
  • If there are multiple sub-strings of different length, choose the one with maximum length.
  • If there is no sub-string that is the same when read forwards and backwards print "None".
  • Sub-string is only valid if its length is more than 1.
  • Strings only contain uppercase characters (A-Z).
  • 1Example 1

    Input
    inputStr = "YABCCBAZ"
    Output
    "ABCCBA"
    Explanation
    Given string is "YABCCBAZ", in this only sub-string which is same when read forward and backward is "ABCCBA".

    2Example 2

    Input
    inputStr = "ABC"
    Output
    "None"
    Explanation
    Given string is "ABC", and no sub-string is present which is same when read forward and backward. So, the output is "None".

    Constraints

    Limits and guarantees your solution can rely on.

    ๐Ÿ…๐Ÿ…
    public String findPalindromeSubString(String inputStr) {
      // write your code here
    }
    
    Input

    inputStr

    "YABCCBAZ"

    Output

    "ABCCBA"

    Sign in to submit your solution.