Zoho String Questions
Zoho String Questions
Question 3:
Given a string of integers find out all the possible words that can
made out of it in continuous order.
Eg: “11112”
ans:
AAAAB
AKAB
AAKB
AAAL
AKL
Note: Take the existing answer alone.
4. Given an expression string exp, write a program to examine
whether the pairs and the orders of “{“, “}”, “(“, “)”, “[“, “]” are
correct in exp.
Example:
Input: exp = “[()]{}{[()()]()}”
Output: Balanced
Input: exp = “[(])”
Output: Not Balanced
#include<stdio.h>
#include<string.h>
int main() {
char x[20];
scanf("%s",x);
int len = strlen(x);
char y[len];
for(int i=0;i<len;i++){
y[i] = 0;
}
int j=0;
//[()]{}{[()()]()}
//[(
for(int i=0;x[i];i++){
if(x[i]=='(' || x[i]=='[' || x[i]=='{'){
y[j] = x[i];
j++;
}
else{
if(x[i]==')' && y[j-1] == '('){
j=j-1;
y[j]=0;
}
else if(x[i]==']' && y[j-1] == '['){
j=j-1;
y[j]=0;
}
else if(x[i]=='}' && y[j-1] == '{'){
j=j-1;
y[j]=0;
}
else{
printf("Not Balanced...");
break;
}
}
}
int m=0;
for(int i=0;i<len;i++){
if(y[i]!=0){
m++;
}
}
if(m==0){
printf("Balanced...");
}
return 0;
}
6666666666666666666666666666666666
Print letter ‘X’ using ‘*’.
#include<stdio.h>
#include<string.h>
int main() {
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j){
printf("*");
}
else if((i+j)==(n-1)){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");
}
return 0;
}
Input: TAMIL
Output:
T L
A I
M
A I
T L
#include<stdio.h>
#include<string.h>
int main(){
char x[20];
scanf("%s",x);
int n = strlen(x);
int h=0;int q=n-1;//This h and q is for moving in the character
array...
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j){
printf("%c",x[h]);
if(h==q){
q--;
}
h++;
}
else if((i+j)==(n-1)){
printf("%c",x[q]);
q--;
}
else{
printf(" ");
}
}
printf("\n");
}
return 0;
}
PROGRAM pattern
Question 3: Given a string, reverse only vowels in it; leaving rest
of the string as it is.
Input : abcdef
Output : ebcdaf
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
#include<stdio.h>
#include<string.h>
int main(){
int n;
scanf("%d",&n);
int k = 1;
int q=n-1;
for(int i=0;i<n;i++){
for(int j=0;j<(n-i-1);j++){
printf(" ");
}
for(;q<(n+n-1-i);q++){
printf("%d\t",k);
(i%2)?k--:k++;
}
(i%2)?(k=(k+n+1)):(k=(k+n-1));
q = q-n-1;
printf("\n");
}
return 0;
}
Given a string, remove the vowels from the string and print the
string without vowels.
Examples:
Input : welcome to geeksforgeeks
Output : wlcm t gksfrgks
#include<stdio.h>
#include<string.h>
int main(){
char x[40];
scanf("%[^\n]s",x);
for(int i=0;x[i];i++){
if(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u'){
x[i]='$';
}
}
printf("%s\n",x);
for(int i=0;x[i];i++){
if(x[i]!='$'){
printf("%c",x[i]);
}
}
return 0;
}
You can solve this one.
Output:
G
GR
GRA
GRAM
GRAMP
GRAMPR
GRAMPRO 18181818181818181818181818181818181818
18181818181818181818181818181818181818
#include<stdio.h>
#include<string.h>
int main() {
char x[20];
scanf("%s",x);
int len = strlen(x);
int h = len/2;
char y[len+1];
int f=0;
for(int i=h;x[i];i++){
y[f] = x[i];
f++;
}
for(int i=0;i<h;i++){
y[f] = x[i];
f++;
}
y[f]='\0';
printf("%s\n",y);
int r=0; int q=(len*2)-2;
for(int i=0;i<len;i++){
for(int j=0;j<(len*2-1);j++){
if(j==q){
int g=0;
for(;g<=r;g++){
printf("%c",y[g]);
}
r++;
j = j+g-1;
break;
}
else{
printf(" ");
}
}
printf("\n");
q = q-2;
}
return 0;
}1
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
919191919191919191919191919191919191919191919191919191
020202020202020202020202020202020202020202020202020202
020202020202020202020202020202020202020202020202020202
020202020202020202020
PROGRAM
G
GR
GRA
GRAM
GRAMP
GRAMPR
GRAMPRO
#include<stdio.h>
#include<string.h>
int main() {
char x[20];
scanf("%s",x);
int len = strlen(x);
int h = len/2;
char y[len+1];
int f=0;
for(int i=h;x[i];i++){
y[f] = x[i];
f++;
}
for(int i=0;i<h;i++){
y[f] = x[i];
f++;
}
y[f]='\0';
int r=0; int q=(len)-1;
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
if(j==q){
int g=0;
for(;g<=r;g++){
printf("%c",y[g]);
}
r++;
j = j+g-1;
break;
}
else{
printf(" ");
}
}
printf("\n");
q = q-1;
}
return 0;
}
212121212121212121212121212121212121212121212121212121
212121212121212121212121212121212121212121212121212121
212121212121212121212121212121212121212121212121Patter
n:2121212121212121212121212121212121212121212121212121
212121212121212121212121212121212121
1 7 12 16 19 21
2 8 13 17 20
3 9 14 18
4 10 15
5 11
6212121
#include<stdio.h>
int main() {
int n;
scanf("%d",&n);
int k=n;
int m=n;
for(int i=1;i<=n;i++){
printf("%d ",i);
int y = i+k;
for(int j=1;j<m;j++){
printf("%d ",y);
k--;
y = y+k;
}
printf("\n");
k=6;
m--;
}
return 0;
}
Question: 7
Given two matrices a and b both of size NxN find if matrix a can
be transformed to matrix b by rotating it 90deg , 180deg , 270deg
if so print TRUE else print FALSE
Input:
123
456
789
987
654
321
Output:
True
Program:
#include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int A[n][n];
for(int i=0;i<n;i++){// Receiving A matrix
for(int j=0;j<n;j++){
scanf("%d",&A[i][j]);
}
}
int C[n][n];
for(int i=0;i<n;i++){//Receiving C Matrix
for(int j=0;j<n;j++){
scanf("%d",&C[i][j]);
}
}
int q = 3;
int v=0;
while(q){
int B[n][n];
int h=0; int k=0;
for(int j=0;j<n;j++){
for(int i=n-1;i>=0;i--){
B[k][h] = A[i][j];
h++;
}
k++;
h=0;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
A[i][j] = B[i][j];
}
}
int count=0;
for(int i=0;i<n;i++){
int x = 0;
for(int j=0;j<n;j++){
if(B[i][j] == C[i][j]){
count++;
}
else{
x++;
break;
}
}
if(x!=0){
break;
}
}
if(count==n*n){
printf("True");
break;
}
else{
v++;
}
q--;
}
if(v==3){
printf("False");
}
return 0;
}
Output :
Minimum Deletion = 2 and
Minimum Insertion = 1
Explanation:
p and h deleted from heap
Then, p is inserted at the beginning
One thing to note, though p was required yet
it was removed/deleted first from its position and
then it is inserted to some other position.
Thus, p contributes one to the deletion_count
and one to the insertion_count.
Example 2:
Input :
str1 = "geeksforgeeks", str2 = "geeks"
Output :
Minimum Deletion = 8
Minimum Insertion = 0
Program:
#include<stdio.h>
#include<string.h>
int main() {
char x[50];
scanf("%s",x);
int len = strlen(x);
char y[len+1];
int max=0; int start=0; int end=0;
int j=0;
for(int i=0;x[i];i++){
char m = x[i];
y[j] = m;j++;
for(int k=i+1;x[k];k++){
char g = x[k];
y[j] = g;j++;
int a =0;
int b=j-1;
int flag = 0;
while(a<b){
if(y[a]!=y[b]){
flag++;break;
}
a++;b--;
}
if(flag==0){
int count = k-i+1;
if(max<count){
max = count;
start = i;
end = k;
}
}
}
j=0;
}
printf("%d %d %d\n",start,end,max);
for(int i=start;i<=end;i++){
printf("%c",x[i]);
}
return 0;
}
Q2. Print all possible subsets of the given array whose sum equal
to given N.
Example:
Input: {1, 2, 3, 4, 5} N=6
Output: {1, 2, 3}, {1, 5}, {2, 4}
Q3. Reverse the words in the given String1 from the first
occurrence of String2 in String1 by maintaining white Spaces.
Example:
Input:
String1: This is a test String only
String2 = st
Output:
This is a only String test
Given a matrix NxN, you are initially in the 0, 0 position. The
matrix is filled with ones and zeros. Value “one” represents the
path is available, while “zero” represents the wall. You need to
find the can you able to reach the (N-1)x(N-1) index in the matrix.
You can move only along the right and down directions if there’s
“one” available.
Input:
5 //N value
10100
11111
00010
10111
01101
Output:
Yes
Zoho Questions:
n=7
1111111
1000001
1011101
1010101
1011101
1000001
1111111
#include<stdio.h>
int main() {
int n;
scanf("%d",&n);
int a = 0; int b=n-1; int c = 0; int d=n-1;
int m = 1;
int A[n][n];
while(a<=b && c<=d){
for(int i=a;i<=b;i++){
A[c][i] = m;
}
c++;
for(int i=c;i<=d;i++){
A[i][b] = m;
}
b--;
for(int i=b;i>=a;i--){
A[d][i] = m;
}
d--;
for(int i=d;i>=c;i--){
A[i][a] = m;
}
a++;
if(m==1)
m=0;
else
m=1;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d ",A[i][j]);
}
printf("\n");
}
}
Input:
racecar
output:
E
C C
A A
R R
A A
C C
E
#include<stdio.h>
#include<string.h>
int main(){
char x[20];
scanf("%s",x);
int len = strlen(x);
if(len%2==0){
printf("Not possible");
}
else{
int i=len/2; int j=len/2;
for(int k=0;k<len;k++){
for(int m=0;m<len;m++){
if(m==i){
printf("%c",x[i]);
break;
}
else if(m==j){
printf("%c",x[j]);
}
else{
printf(" ");
}
}
if(k<(len/2)){
i++;j--;
}
else if(k==(len/2)){
j = j+1;
i = i-1;
}
else{
j++;i--;
}
printf("\n");
}
}
return 0;
}
Questions:
Given an amount, find the minimum number of notes of
different denominations that sum upto the given amount.
Starting from the highest denomination note, try to
accommodate as many notes possible for given amount.
We may assume that we have infinite supply of notes of
values {2000, 500, 200, 100, 50, 20, 10, 5, 1}
Examples:
Input: 800
Output: Currency Count
500: 1
200: 1
100: 1
Input: 2456
Output: Currency Count
2000: 1
200: 2
50: 1
5: 1
1: 1
Examples:
Input: Hexadecimal = 1AC5
Output: Binary = 0001101011000101
Explanation:
Equivalent binary value of 1: 0001
Equivalent binary value of A: 1010
Equivalent binary value of C: 1100
Equivalent binary value of 5: 0101
#include <stdio.h>
// function to convert Hexadecimal to Binary
Number
void HexToBin(char* hexdec)
{
long int i = 0;
while (hexdec[i]) {
switch (hexdec[i]){
case '0':
printf("0000");
break;
case '1':
printf("0001");
break;
case '2':
printf("0010");
break;
case '3':
printf("0011");
break;
case '4':
printf("0100");
break;
case '5':
printf("0101");
break;
case '6':
printf("0110");
break;
case '7':
printf("0111");
break;
case '8':
printf("1000");
break;
case '9':
printf("1001");
break;
case 'A':
case 'a':
printf("1010");
break;
case 'B':
case 'b':
printf("1011");
break;
case 'C':
case 'c':
printf("1100");
break;
case 'D':
case 'd':
printf("1101");
break;
case 'E':
case 'e':
printf("1110");
break;
case 'F':
case 'f':
printf("1111");
break;
default:
printf("\nInvalid hexadecimal digit %c",
hexdec[i]);
}
i++;
}
}
int main()
{
// Get the Hexadecimal number
char hexdec[100] = "1AC5";
// Convert HexaDecimal to Binary
printf("\nEquivalent Binary value is : ");
HexToBin(hexdec);
}
Input: S = "A&B"
Output: "B&A"
Explanation: As we ignore '&' and
then reverse, so answer is "B&A".
​Example 2:
Input: S = "A&x#
Output: "x&A#"
Explanation: we swap only A and x.