Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Zoho String Questions

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 41

1111111111111111

1. Count the numbers of characters in the given string treating ‘$’


as escape sequence. If ‘$’ is preceeded by ”, consider it as normal
‘$’ and not the escape sequence. If ” occurs, treat it as single ”.
Example:
Input: Hello$World$
Output: 11

2. Print true if second string is a substring of first string, else print


false.
Note: * symbol can replace n number of characters
Input:
Spoon Sp*n Output : TRUE
Zoho *o*o Output : TRUE
Man n* Output : TRUE
Subline *line Output : TRUE
#include<stdio.h>
int main() {
char x[10];
char y[10];
scanf("%s",x);
scanf("%s",y);
int i=0;int j=0;
while(x[i] && y[j]){
if(x[i]==y[j]){
i++;j++;
}#
else if(y[j]=='*' && (x[i]>='a' && x[i]<='z' || x[i]>='A' &&
x[i]<='Z')){
if(x[i+1] == y[j+1]){
i++;j++;
}
else{
i++;
}
}
else{
i++;
}
}
if(x[i]=='\0' && y[j]=='\0')
printf("true");
else
printf("false");
return 0;
}

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

Zoho Interview: Off campus - 2021:


Alphabets are inside () and the number -9<=0>=9 which is under{}
solve the string according to the sample input output
Input (z){-2}oho
Output ZZoho
Input ((X){2}(y){3}(z)){2}
Output xxyyyzxxyyyz

1. Write a program to print a snake matrix in the following pattern


without using arrays and if conditions.
Input: 4
Output:

      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;
}

Pattern Searching: (Naïve Algorithm)


Input: txt[] = "THIS IS A TEST TEXT"
pat[] = "TEST"
Output: Pattern found at index 10

Input: txt[] = "AABAACAADAABAABA"


pat[] = "AABA"
Output: Pattern found at index 0
Pattern found at index 9
Pattern found at index 12
You can solve this one.
//Naive Algorithm
#include<stdio.h>
#include<string.h>
int main(){
char x[50];
char y[10];
scanf("%[^\n]s",x);
scanf("%s",y);
int len = strlen(y);
for(int i=0;x[i];i++){//x's length => len1
char m = x[i];
int count=0;
for(int j=0;y[j];j++){//it works only once
char k = y[j];
if(m==k){
count++;
for(int t=1,f=i+1;y[t];t++,f++){//y's length => len2
if(y[t]==x[f]){
count++;
}
else{
break;
}
}
}
if(count==len){
printf("%d\n",i);
break;
}
else{
break;
}
}
}
return 0;
}
//O(len1*len1)
//len1 is x's length
//len2 is y's length

Given a string, remove the vowels from the string and print the
string without vowels.
Examples:
Input : welcome to geeksforgeeks
Output : wlcm t gksfrgks

Input : what is your name ?


Output : wht s yr nm ?

#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.

Given a string s of lowercase letters, we need to remove


consecutive vowels from the string
Note : Sentence should not contain two consecutive vowels ( a, e,
i, o, u).
Examples :
Input: geeks for geeks
Output: geks for geks
Input : your article is in queue
Output : yor article is in qu
#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'){
for(int j=i+1;x[j];j++){
if(!(x[j]=='a'||x[j]=='e'||x[j]=='i'||x[j]=='o'||x[j]=='u')){
printf("%c",x[i]);
i=j-1;
break;
}
}
}
else{
printf("%c",x[i]);
}
}
return 0;
}

You can solve this one.


171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
717171717171717171717171717171717171717171717171717171
7171717171717171717
Input:1
818181818181818181818181818181818181818181818181818181
818181818181818181818181818181818181818181818
PROGRAM

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;
}

2. You’re given an even number n.


If n=4, you have to print the following pattern:
4444
4334
4334
4444
If n=6, then the pattern should be like this :
666666
655556
654456
654456
655556
666666
Program:
#include<stdio.h>
int main() {
int n;
scanf("%d",&n);
int m = n;
int A[n][n];
int a=0; int b=n-1; int c=0;int d=n-1;
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++;
m--;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
printf("%d",A[i][j]);
}
printf("\n");
}
return 0;
}

4. Write function to find multiplication of 2 numbers using


+ operator. You must use minimum possible iterations.
Input: 3, 4
Output 12
Given two strings ‘str1’ and ‘str2’ of size m and n respectively.
The task is to remove/delete and insert the minimum number of
characters from/in str1 to transform it into str2. It could be
possible that the same character needs to be removed/deleted from
one point of str1 and inserted to some another point.
Example 1: 
Input :
str1 = "heap", str2 = "pea"

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

Given a string, find the longest substring which is palindrome. 


For example, 
Input: Given string :"forgeeksskeegfor"
Output: "geeksskeeg"
Input: Given string :"Geeks",
Output: "ee"

Brute Force Method.

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

Given an array of integers, compute the maximum value for each


integer in the index, by either summing all the digits or
multiplying all the digits. (Choose which operation gives the
maximum value)
Input:
5
120 24 71 10 59
Output:
3 8 8 1 45
Explanation: For index 0, the integer is 120. Summing the digits
will give 3, and whereas Multiplying the digits gives 0. Thus,
maximum of this two is 3.

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

Given a Hexadecimal number as an input, the task is to


convert that number to a Binary number.

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

Input: Hexadecimal = 5D1F


Output: Binary = 0101110100011111

Approach: A hexadecimal number is a positional numeral


system with a radix, or base, of 16 and uses sixteen distinct
symbols.
A binary number is a number expressed in the base-2
binary numeral system, which uses only two symbols: which
are 0 (zero) and 1 (one).

#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);
}

Given a string S, containing special characters and all the


alphabets, reverse the string without
affecting the positions of the special characters.
Example 1:

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.

Given a matrix of N*M order. Find the shortest distance from a


source cell to a destination cell, traversing through limited cells
only. Also you can move only up, down, left and right. If found
output the distance else -1. 
s represents ‘source’ 
d represents ‘destination’ 
* represents cell you can travel 
0 represents cell you can not travel 
This problem is meant for single source and destination.
Examples: 
Input: {'0', '*', '0', 's'},
{'*', '0', '*', '*'},
{'0', '*', '*', '*'},
{'d', '*', '*', '*'}
Output: 6

Input: {'0', '*', '0', 's'},


{'*', '0', '*', '*'},
{'0', '*', '*', '*'},
{'d', '0', '0', '0'}
Output: -1

Given a 6 blocks, of different height h1, …, h6 . Make 2


towers using 3 Blocks for each tower in desired height h1,
h2. Print the blocks to be used in ascending order
Input:
1 2 5 4 3 6
height of tower: 6 15
Output:
123&456

You might also like