Lapindrome problem

Can i solve Lapindrome problem without using map function (in c++) ?
problem link:

I did it without the use of map or vector or array .
I simply ran a loop over all the elements of the string, but now I can tell you that it would’ve been much easier if you used vector/array/map .
If you need an explanation for my solution reply to this message and I will explain it -
https://www.codechef.com/viewsolution/33071297
Again, the code would have been much shorter with the use of array although the time complexity would’ve been same (but using map space complexity would be more) .

1 Like

Invalid solution id showing!

@shubhamkumar68
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
for(cin>>t;t;–t)
{
string s,r1,r2;
cin>>s;
int len=s.length();
if(len%2!=0)
{ for(int i=0;i<len/2;++i)
r1.push_back(s[i]);
for(int i=len/2+1;i<len;++i)
r2.push_back(s[i]);
sort(r1.begin(),r1.end());
sort(r2.begin(),r2.end());
if(r1.compare(r2)==0) cout<<“YES\n”;
else cout<<“NO\n”;
}
else
{
for(int i=0;i<len/2;++i)
r1.push_back(s[i]);
for(int i=len/2;i<len;++i)
r2.push_back(s[i]);
sort(r1.begin(),r1.end());
sort(r2.begin(),r2.end());
if(r1.compare(r2)==0) cout<<“YES\n”;
else cout<<“NO\n”;
}
}
return 0;
}`
Check this it will Help you… :slight_smile:

1 Like

https://www.codechef.com/viewsolution/30878373
Hope it helps you.It is in java but you can understand the logic.

1 Like

I’d do it like this.

1 Like

sorry . I have edited the link , take a look again .

1 Like

Here is a very simple solution without using map/vector/arrays etc.

https://www.codechef.com/viewsolution/34899848

1 Like