using
System;
class
GFG
{
static
bool
isPalindrome(
string
str,
int
low,
int
high)
{
while
(low < high)
{
if
(str[low] != str[high])
return
false
;
low++;
high--;
}
return
true
;
}
static
int
possiblePalinByRemovingOneChar(
string
str)
{
int
low = 0, high = str.Length - 1;
while
(low < high)
{
if
(str[low] == str[high])
{
low++;
high--;
}
else
{
if
(isPalindrome(str, low + 1, high))
return
low;
if
(isPalindrome(str, low, high - 1))
return
high;
return
-1;
}
}
return
-2;
}
public
static
void
Main(String[] args)
{
string
str =
"abecbea"
;
int
idx = possiblePalinByRemovingOneChar(str);
if
(idx == -1)
Console.Write(
"Not Possible"
);
else
if
(idx == -2)
Console.Write(
"Possible without "
+
"removing any character"
);
else
Console.Write(
"Possible by removing"
+
" character at index "
+ idx);
}
}