Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Marut and Strings problem solution

YASH PAL, 31 July 202414 February 2026
In this HackerEarth Marut and Strings problem solution Marut loves good strings. According to him, good strings are those which contain either all alphabets of uppercase or lowercase. While he is preparing for his exams, he finds many bad strings in his book and wants to convert them to good strings. But he wants to do this in minimum number of operations.
 
In one operation, he can pick only one character of any case and convert it to any other case.
 
As his exams are going on, he wants your help.
 
 
HackerEarth Marut and Strings problem solution

 

 

HackerEarth Marut and Strings problem solution.

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <set>
#include <assert.h>
#include <cstring>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <time.h>
#include <climits>

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FORR(i,a,b) for(int i=a;i>=b;--i)
#define FORC(it,container) for(typeof(container.begin()) it=container.begin();it!=container.end();++it)
#define INT(x) scanf("%d",&x)
#define LLD(x) scanf("%lld",&x)
#define STR(x) scanf("%s",x)
#define CHAR(x) scanf("%c",&x)
#define PINT(x) printf("%dn",x)
#define PLLD(x) printf("%lldn",x)
#define CLR(x) memset(x,0,sizeof(x));
#define F first
#define S second
#define PB push_back

const int INF = INT_MAX;
const int MAX = 100005;
const int MOD = 1e9 + 7;

int main()
{
freopen("in","r",stdin);
freopen("out","w",stdout);
int test;
cin>>test;
if (test<1 || test>10)
{
cout<<"Invalid Test";
return 0;
}
while(test--)
{

string s;
cin>>s;

int len = s.length();

if(len<1 || len>100000)
{
cout<<"Invalid Inputn";
continue;
}
int ans=0;
int ans1=0,ans2=0;

FOR(i,0,len) {

assert((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'));

if(s[i]>='a' && s[i]<='z')
++ans1;
else if(s[i]>='A' && s[i]<='Z')
++ans2;

}

ans = min(ans1,ans2);
cout<<ans<<endl;

}
return 0;
}
 

Second solution

#include <bits/stdc++.h>
using namespace std;

int main()
{
int T;
cin>>T;
assert(T>=1 && T<=10);
while(T--)
{
int l=0,u=0;
char str[100001];
cin>>str;
int len=strlen(str);

assert(len>=1 && len<=100000);
for(int i=0;str[i]!='';i++)
{
assert((str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z'));
if(islower(str[i]))
l++;
else
u++;
}

cout<<min(l,u)<<endl;
}
return 0;
}
 
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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