File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change
1
+ /* Given a string A consisting only of lowercase characters, we need to check whether it is possible to make
2
+ this string a palindrome after removing exactly one character from this.
3
+
4
+ If it is possible then print "1" else print "0" (without quotes).
5
+ 3 <= |A| <= 105
6
+ A[i] is always a lowercase character.
7
+
8
+ Input Format
9
+ First and only argument is an string A.
10
+
11
+ Output Format
12
+ Print 1 if it is possible to convert A to palindrome by removing exactly one character else print 0.
13
+ */
14
+
15
+
1
16
# include < bits/stdc++.h>
2
17
using namespace std ;
3
18
4
19
int main ()
5
20
{
6
21
string A;
7
22
cin>>A;
8
- int n = A.size ();
23
+ int n = A.size (); // n is the size of the given string
9
24
int i=0 , j=n-1 , count=0 ;
10
- while (i<j)
25
+ while (i<j) // using two pointer approach with O(n) time complexity
11
26
{
12
- if (A[i]== A[j])
27
+ if (A[i] == A[j]) // comparing first and last character of string
13
28
{
14
29
i++;
15
30
j--;
You can’t perform that action at this time.
0 commit comments