Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Xsquare And Double Strings problem solution

YASH PAL, 31 July 2024
In this HackerEarth Xsquare And Double Strings problem solution, Xsquare got bored playing with the arrays all the time. Therefore, he has decided to play with the strings. Xsquare called a string P a “double string” if string P is not empty and can be broken into two strings A and B such that A + B = P and A = B. for eg : strings like “baba” , “blabla” , “lolo” are all double strings whereas strings like “hacker” , “abc” , “earth” are not double strings at all.
Today, Xsquare has a special string S consisting of lower case English letters. He can remove as many characters ( possibly zero ) as he wants from his special string S. Xsquare wants to know , if its possible to convert his string S to a double string or not.
Help him in accomplishing this task.
HackerEarth Xsquare And Double Strings problem solution

HackerEarth Xsquare And Double Strings problem solution.

#include <bits/stdc++.h>
using namespace std ;
#define LL long long int
#define ft first
#define sd second
#define PII pair<int,int>
#define MAXN 100005
#define MAXM 10000001
#define mp make_pair
#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
#define pr(x) printf("%dn",x)
#define pb push_back
#define MOD 1000000007
#define MAX 1000010
#define ull long long
#define prime 37
#define pb push_back
#define ASST(x,y,z) assert(x >= y && x <= z)

int t , n;
string s ;
int main(){
f_in("in02.txt") ;
f_out("out02.txt") ;
sc(t) ;
ASST(t,1,100) ;
while(t --){
cin >> s ;
n = s.length() ;
ASST(n,1,100) ;
int M[26]={0} , c = 0;
for(int i=0;i<n;i++) ASST(s[i],'a','z') ;
bool ok = false ;
for(int i=0;i<n;i++) M[s[i]-'a'] ++ ;
for(int i=0;i<26;i++) if(M[i] > 1) ok = true ;
puts(ok ? "Yes" : "No") ;
}
return 0 ;
}

Second solution

#include <bits/stdc++.h>

using namespace std;

int cnt[32];

int main()
{
int t;
string s;
cin >> t;
while ( t-- ) {
cin >> s;
memset(cnt, 0, sizeof(cnt));
for ( int i = 0; i < s.size(); i++ ) cnt[s[i]-'a']++;
for ( int i = 0; i < 26; i++ ) {
if ( cnt[i] >= 2 ) {
printf("Yesn");
goto p1;
}
}
printf("Non");
p1: { }
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes