Skip to content
Programmingoneonone
Programmingoneonone
  • 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

HackerEarth Arjit and Printing Press problem solution

YASH PAL, 31 July 2024
In this HackerEarth Arjit and Printing Press problem solution Arjit has his own printing press, Bainik Dhaskar (BD). He feels that words on their own simply aren’t beautiful enough. So, he wishes to make a Super Manuscript (SM) machine. Now what does this machine do?
The SM machine aims to make words as beautiful as they can be by making a word as lexicographically small as possible. Arjit, being the resourceful person he is, has a reserve string from which we can choose characters that will replace characters in the original word that BD’s SM machine wishes to transform.
Keep in mind that once you have used a letter in the reserve string, it is removed from the reserve.
As Arjit is busy with other work at BD, it’s your work to take care of programming SM 🙂
Note that you cannot modify the original order of the letters in the word that has to be transformed. You can only replace its letters with those in the reserve.
HackerEarth Arjit and Printing Press problem solution

HackerEarth Arjit and Printing Press problem solution.

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e4 + 5;
char W[maxn], R[maxn];

int main()
{
int t;
scanf("%d", &t);
while (t--)
{
scanf("%s%s", W, R);
vector<int> cnt(26);
for (int i = 0; R[i]; i++)
cnt[R[i] - 'a']++;
for (int i = 0; W[i]; i++)
for (int j = 0; j < 26; j++)
if (cnt[j] > 0)
if (j + 'a' < W[i])
{
W[i] = j + 'a';
cnt[j]--;
break;
}
printf("%sn", W);
}
return 0;
}

Second solution

#include<iostream>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <assert.h>
using namespace std;
int main()
{
int t;
cin>>t;
assert(t>=1 && t<=10);
while (t--)
{
string w,r;
cin>>w>>r;
assert(w.size()>=1 && w.size()<=10000);
assert(r.size()>=1 && r.size()<=10000);
sort(r.begin(),r.end());
int i,j=0;
for(i=0;i<w.size()&&j<r.size();i++)
{
if(w[i]>r[j])
{
w[i]=r[j];
j++;
}
}
cout<<w<<endl;
}
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