Move hash | Capgemini coding question
Problem:-
You have write a function that accepts, a string that has some “#”, in it you have to move all the hashes to the front of the string and return the whole string back .
Here You have to complete char* moveHash(char str[],int n);
Sample input :
easy#coding#zone
Sample output:
##easycodingzone
Move hash | Capgemini coding question
The objective of the code is to move all the hashes at the starting of the string . You just have to complete the function moveHash(char str[],int n);
C++ code:-
#include<bits/stdc++.h>
using namespace std;
// function for moving hash
char *moveHash(char str[],int n)
{
for(int i=0;i<n;i++)
{
if(str[i]=='#')
{
int j=i;
while(j>0)
{
char ch=str[j];
str[j]=str[j-1];
str[j-1]=ch;
j--;
}
}
}
return str;
}
// driver function
int main()
{
char s[5000];
cin>>s;
int len=strlen(s);
cout<<moveHash(s,len);
return 0;
}
Python code:-
def movehash(s1):
n=s1.count("#")
s1=s1.replace("#","")
for i in range(n):
s1="#"+s1
return s1
s=input()
print(movehash(s))
Companies interview:-
- Swap adjacent characters
- Double the vowel characters
- Check valid parenthesis
- Print the characters with their frequencies
- Find closest value
- Word Count
- Program of CaesarCipher
- Program to find the perfect city
- Annual Day | Tech Mahindra coding question
- Find the number of pairs in the array whose sum is equal to a given target.
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
See more:-
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
0 Comments