Skip to content

Commit

Permalink
Merge pull request #383 from Khushm/main
Browse files Browse the repository at this point in the history
Added one competitive programming question in Task 1 folder #5
  • Loading branch information
nimishbongale authored Oct 27, 2021
2 parents 4215859 + 3cb7ea0 commit d676698
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Task 1/Lapindrome/Question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Problem Statement:
Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same frequency of each character. If there are odd number of characters in the string, we ignore the middle character and check for lapindrome. For example gaga is a lapindrome, since the two halves ga and ga have the same characters with same frequency. Also, abccab, rotor and xyzxy are a few examples of lapindromes. Note that abbaab is NOT a lapindrome. The two halves contain the same characters but their frequencies do not match.
Your task is simple. Given a string, you need to tell if it is a lapindrome.

Input:
First line of input contains a single integer T, the number of test cases.
Each test is a single line containing a string S composed of only lowercase English alphabet.

Output:
For each test case, output on a separate line: "YES" if the string is a lapindrome and "NO" if it is not.

Constraints:
1 ≤ T ≤ 100
2 ≤ |S| ≤ 1000, where |S| denotes the length of S

Example:
Input:
6
gaga
abcde
rotor
xyzxy
abbaab
ababc

Output:
YES
NO
YES
YES
NO
NO
38 changes: 38 additions & 0 deletions Task 1/Lapindrome/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>
#include <algorithm>
using namespace std;

bool checkPalindrome(string str){
int len = str.size();
string str1 = "";
string str2 = "";

for(int i=0;i<len/2;i++)
str1+=str[i];

if(len%2 == 0){
for(int i=len/2;i<len;i++)
str2+=str[i];
}
else{
for(int i=(len/2)+1;i<len;i++)
str2+=str[i];
}
sort(str1.begin(),str1.end());
sort(str2.begin(),str2.end());
return (str1.compare(str2) == 0);
}

int main() {
string str;
int test;
cin >> test;
while(test--){
cin >> str;
if(checkPalindrome(str))
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}

0 comments on commit d676698

Please sign in to comment.