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 Illegible String problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Illegible String problem solution, Your friend Max has written a string S in your textbook. The string consists of lowercase Latin letters. The problem is that Max is not good at writing at all! Especially, you never know if he wanted to write “w” or two consecutive “v”. Given the string S, return the minimum and maximum length of a word which can be represented by it. The input string represents what you initially think the word is.
 
 
HackerEarth Illegible String problem solution

 

 

HackerEarth Illegible String problem solution.

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define SZ(x) ((int)(x.size()))
#define fi first
#define se second
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;

typedef long long ll;

int main()
{
ios_base::sync_with_stdio(0);
string s;
int n;
cin >> n;
cin >> s;
int m = 0, M = 0;
int run_w = 0, run_v = 0;
FOR(i, n)
{
if(s[i] == 'v') run_v++;
else if(s[i] == 'w') run_w++;
else
{
++m;
++M;
int vs = 2 * run_w + run_v;
M += vs;
m += ceil(vs / 2.0);
run_v = 0;
run_w = 0;
}
}
int vs = 2 * run_w + run_v;
M += vs;
m += ceil(vs / 2.0);
cout << m << " " << M << endl;

return 0;
}
 
 

Second solution

#include <bits/stdc++.h>

using namespace std;

string st;
int n;
int cnt,ans1,ans2;

int main(){

cin>>n;
cin>>st;

for (int i=0;i<st.size();i++)
{
if (st[i]=='v')
{
cnt++;
continue;
}
if (st[i]=='w')
{
cnt+=2;
continue;
}
ans1+=cnt;
ans2+=cnt/2+cnt%2;
cnt=0;
++ans1;
++ans2;
}

ans1+=cnt;
ans2+=cnt/2+cnt%2;

cout<<ans2<<" "<<ans1<<endl;

//cin.get();cin.get();
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