Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
in Online Assessments by Expert (110,880 points) | 810 views

1 Answer

0 like 0 dislike

problem Statement: Write a function that will accept a string whose length is “len”, the string has some “#” keywords in it. Now move all the hashes ‘#’ to the front of the string and return the whole string back and last print it.

Sample Test Case:

Input: The#Learn#Programo

Output: ###TheLearnProgramo

Program in C++:

//Learnprogramo - programming made simple
using namespace std;
char *moveHash(char str[], int len) 
//Initilizing the required variables
char result[100], resultHash[100];
int j=0, k=0, i;
//Iterate on string
for(i=0; i<len; i++) 
//If hash found then adding # keyword in resultHash string and continue the loop
if(str[i] == '#') {
resultHash[k] = '#';
//Here means not '#' char so adding original in result
result[j] = str[i];
int main() 
//Initilizing the required variables
char str[100];
int len;
//Calculating length of string
len = strlen(str);
moveHash(str, len);
by Expert (110,880 points)