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 Chandu and chandni’s secret chat problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Chandu and chandni’s secret chat problem solution, Chandu and chandni Talk on phone for a long time daily. Being afraid that someone will hear their private conversation chandu suggested chandni an idea. He suggested that he will talk only with encrypted strings with her and only she would know, how to decrypt the string. So that even if someone hears, He/She would not be able to anticipate their conversation.
 
Rules of encryption are as follows:
1. String on length N is assumed to be cyclic consisting of lower case English alphabets.
2. In each iteration, we pick the last character and put it in starting of the string. For example: april performing iterations and collecting each string formed in a set until we get the original string. Ex: {april,lapri, ilapr, rilap, prila}
3. sort the set of string in lexicographically reverse order. Ex: {rilap, prila,lapri, ilapr, april }
4. Taking the last character of each string in the set is the encrypted string. Ex: pairl
 
Chandu also sends the position(K) of first letter in encrypted string from original string i.e 2 (p is on position 2 in original string and is the first character of encrypted string)
 
Now, Chandni is ofcourse not that brilliant to decrypt the strings in real time and understand what chandu is saying. So, chandu decided to write a program for the same.
 
Help chandu write this program.
 
 
HackerEarth Chandu and chandni's secret chat problem solution

 

 

HackerEarth Chandu and Chandni’s secret chat problem solution.

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

#define st_clk double st=clock();
#define end_clk double en=clock();
#define show_time cout<<"tTIME="<<(en-st)/CLOCKS_PER_SEC<<endl;


#define f_in(st) freopen(st,"r",stdin);
#define f_out(st) freopen(st,"w",stdout);

#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;


char str[3005];

bool comp(int i,int j){
return (str[i]!=str[j])? str[i]>str[j]: i<j;
}


int main(){
#ifndef ONLINE_JUDGE
f_in("in5");
f_out("out5");
#endif
int t,n,i,in[3001];
scanf("%d",&t);
while(t--){
scanf("%s%d",str,&n);
n--;
for(i=0;str[i]!='';i++) in[i]=i;
sort(in,in+i,comp);
for(i=0;str[i]!='';i++,n=in[n]) putchar(str[n]);
puts("");
}
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