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

YASH PAL, 31 July 202413 February 2026
In this HackerEarth String Operations problem solution, You are given a string S.
 
Q number of operations are performed on string S.
In each of these Q operations, you are given an index ind and a character ch. For each operation, you have to update the character at index ind in string S to ch, that is, after this operation S[ind] = ch.
It is guaranteed that any index is updated at most once.
We call the final string after performing the Q number of operations as str.
 
After this, M number of operations are performed on string str.
In each of these M operations, you are given two indices a and b. For each operation, you have to reverse the substring that lies between the indices a and b (inclusive).
We call the final string after performing M operations as fin.
 
 
HackerEarth String Operations problem solution

 

 

HackerEarth String Operations problem solution.

import java.util.*;
import java.lang.*;

class StringQue
{
public static void main(String args[])
{
StringBuffer s= new StringBuffer();
Scanner in= new Scanner(System.in);
s.append(in.nextLine());
int q=in.nextInt();
for(int i=1;i<=q;i++)
{
int ind=in.nextInt();
char ch=in.next().charAt(0);
s.setCharAt(ind-1,ch);
}
StringBuffer str=new StringBuffer(s);
int m=in.nextInt();
for(int i=1;i<=m;i++)
{
int a=in.nextInt(),b=in.nextInt(),ans=0;
StringBuffer upd=new StringBuffer();
upd.append(s.substring(a-1,b));
upd.reverse();
s.replace(a-1,b,upd.toString());
}
int ans=0;
System.out.println(str);
System.out.println(s);
for(int i=0;i<s.length();i++)
{
if(str.charAt(i)==s.charAt(i))
ans++;
}
System.out.println(ans);
}
}
 
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