Skip to content

Commit fddebc1

Browse files
committed
Comments added in ConvertToPalindrome file
1 parent dbd5ab7 commit fddebc1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Strings/ConvertToPalindrome_Strings.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
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+
116
# include<bits/stdc++.h>
217
using namespace std;
318

419
int main()
520
{
621
string A;
722
cin>>A;
8-
int n = A.size();
23+
int n = A.size(); //n is the size of the given string
924
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
1126
{
12-
if(A[i]==A[j])
27+
if(A[i] == A[j]) //comparing first and last character of string
1328
{
1429
i++;
1530
j--;

0 commit comments

Comments
 (0)