K3AU01-Editorial

PROBLEM LINK:

Practice
Contest

Author: Dev Bhaskar Singh
Tester: Divyank Goyal
Editorialist: Anugya Jain

DIFFICULTY:

EASY.

PREREQUISITES:

Palindrome and basic programming knowledge .

PROBLEM:

Given a string s of size N of lowercase characters, you have to verify whether the given string is Pretty Palindrome or not.

Pretty Palindrome - A string is said to be Pretty Palindrome if after performing at most k operations, string s will become palindromic in nature.

Operation - In one operation you can change any character of the string to any lower case character.

EXPLANATION:

The palindromic string is a string that reads the same as forward and backward.
To make the string palindromic,
1st character should be equal to last character of string s,
2nd character should be equal to second last character of string s,
3rd character should be equal to third last character of string s,
and so on …
count if the characters are not the same and if the count value is greater than k then return false else return true.

SOLUTIONS:

Editorialist's Solution
//Fly_
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        int count=0;
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[n-i-1])
            count++;
        }
        if(count<=k)
            cout<<"True"<<"\n";
        
        else
        cout<<"False"<<"\n";
    }
}