My issue
i have tried to use two pointer approach . keeping one at beginning and one at ending , if they are not equal i swapped it and made count++ and moved inside else
without swapping moved inside , i ran loop for n/2 times
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int count = 0;
for (int i = 0; i < n; i++)
{
cin >> s[i];
}
for (int i = 0; i < n; i++)
{
// cout<<s[i];
}
for (int i = 0, j = s[n - 1]; i < n / 2; i++, j--)
{
if (s[i] != s[j])
{
count++;
swap(s[i], s[n - 1]);
}
}
cout << count;
}
Problem Link: Reverse String Practice Coding Problem - CodeChef