Skip to content
Programming101
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • 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
Programming101
Programmingoneonone

Learn everything about programming

HackerEarth Marut and Strings problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes