Sunday, 3 September 2017

Home Page

 Zoho Interview Questions


                              4444444 
                              4333334 
                              4322234 
                              4321234 
                              4322234 
                              4333334 
                              4444444
                          000000000
                          010000010 
                          012000210
                          012303210 
                          012343210
                          012303210 
                          012000210 
                          010000010 
                          000000000   
 Practice Yourself  Complex Coding Asked in Zoho
    • Hospital Management System
    • Student Database Management System
    • Railway Reservation System
    • Contact Management System
    • Library Management System
    • Snake Game
    • Call Taxi Booking System
    Zoho Puzzle Questions With Answers

    Sunday, 13 August 2017

    Merge Sort

    #include<stdlib.h>
    #include<stdio.h>
    void merge(int arr[], int l, int m, int r)
    {
        int i, j, k;
        int n1 = m - l + 1;
        int n2 =  r - m;
        // create temp arrays
        int L[n1], R[n2];
        // Copy data to temp arrays L[] and R[]
        for (i = 0; i < n1; i++)
            L[i] = arr[l + i];
        for (j = 0; j < n2; j++)
            R[j] = arr[m + 1+ j];
         // Merge the temp arrays back into arr[l..r]
        i = 0; // Initial index of first subarray
        j = 0; // Initial index of second subarray
        k = l; // Initial index of merged subarray
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }
         // Copy the remaining elements of L[], if there are any
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }
        // Copy the remaining elements of R[], if there are any
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }
    // l is for left index and r is right index of the sub-array of arr to be sorted
    void merge_Sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Same as (l+r)/2, but avoids overflow for large l and h
            int m = l+(r-l)/2;
     
            // Sort first and second halves
            merge_Sort(arr, l, m);
            merge_Sort(arr, m+1, r);
     
            merge(arr, l, m, r);
        }
    }
    // Function to print an array
    void print_Array(int A[], int size)
    {
        int i;
        for (i=0; i < size; i++)
            printf("%d ", A[i]);
        printf("\n");
    }

    int main()
    {
        int arr[] = {12, 11, 13, 5, 6, 7};
        int arr_size = sizeof(arr)/sizeof(arr[0]);
     
        printf("Given array is \n");
        print_Array(arr, arr_size);
     
        merge_Sort(arr, 0, arr_size - 1);
     
        printf("\nSorted array is \n");
        print_Array(arr, arr_size);
        return 0;
    }

    Insertion Sort

    #include <stdio.h>
    #include <math.h>
    Function to sort an array using insertion sort
    void insertion_Sort(int arr[], int n)
    {
    int i, key, j;
    for (i = 1; i < n; i++)
    {
    key = arr[i];
    j = i-1;
    Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position
    while (j >= 0 && arr[j] > key)
    {
    arr[j+1] = arr[j];
    j = j-1;
    }
    arr[j+1] = key;
    }
    }
    A utility function ot print an array of size n
    void print_Array(int arr[], int n)
    {
    int i;
    for (i=0; i < n; i++)
    printf("%d ", arr[i]);
    printf("\n");
    }
     
    int main()
    {
    int arr[] = {12, 11, 13, 5, 6};
    int n = sizeof(arr)/sizeof(arr[0]);
    insertion_Sort(arr, n);
    print_Array(arr, n);
    return 0;
    }

    Bubble Sort

    #include <stdio.h>

    void swap(int *xp, int *yp)
    {
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
    }
    A function to implement bubble sort
    void bubble_Sort(int arr[], int n)
    {
    int i, j;
    for (i = 0; i < n-1; i++)
    Last i elements are already in place
    for (j = 0; j < n-i-1; j++)
    if (arr[j] > arr[j+1])
    swap(&arr[j], &arr[j+1]);
    }
    Function to print an array
    void printArray(int arr[], int size)
    {
    int i;
    for (i=0; i < size; i++)
    printf("%d ", arr[i]);
    printf("n");
    }

    int main()
    {
    int arr[] = {64, 34, 25, 12, 22, 11, 90};
    int n = sizeof(arr)/sizeof(arr[0]);
    bubble_Sort(arr, n);
    printf("Sorted array: \n");
    printArray(arr, n);
    return 0;

    Selection Sort

    #include <stdio.h> 
    void swap(int *xp, int *yp)
    {
        int temp = *xp;
        *xp = *yp;
        *yp = temp;
    }
    void selectionSort(int arr[], int n)
    {
        int i, j, min_index;
         One by one move boundary of unsorted subarray
        for (i = 0; i < n-1; i++)
        {
             Find the minimum element in unsorted array
            min_index = i;
            for (j = i+1; j < n; j++)
              if (arr[j] < arr[min_index])
                min_index = j;
             Swap the found minimum element with the first element
            swap(&arr[min_index], &arr[i]);
        }
    }
     Function to print an array
    void printArray(int arr[], int size)
    {
        int i;
        for (i=0; i < size; i++)
            printf("%d ", arr[i]);
        printf("\n");
    }
    int main()
    {
        int arr[] = {64, 25, 12, 22, 11};
        int n = sizeof(arr)/sizeof(arr[0]);
        selectionSort(arr, n);
        printf("Sorted array: \n");
        printArray(arr, n);
        return 0;
    }

    Write a C program to find whether a given matrix is an upper triangular matrix or not.

                                        UPPER TRIANGULAR MATRIX
                                            
                                                  C-Solution
    #include<stdio.h>
    #include<stdlib.h>
    int **create(int r,int c)
    {
    int **mat,i;
    mat=(int **)malloc(r*sizeof(int *));
    for(i=0;i<r;i++)
    {
    *(mat+i)=(int *)malloc(c*sizeof(int ));
    }
    return mat;
    }
    int **getelement(int **m,int r,int c)
    {
    int i,j;
    for(i=0;i<r;i++)
    {
    for(j=0;j<c;j++)
    {
    scanf("%d",*(m+i)+j);
    }
    }
    return m;
    }
    void exec(int **m,int r,int c)
    {
    int i,j,c1=1;
    for(i=0;i<r;i++)
    {
    for(j=0;j<c;j++)
    {
    if((j<i)&&*(*(m+i)+j)!=0)
    {
    c1=0;
    }
    }
    }
    if(c1==1)
    {
    printf("yes");
    }
    else
    {
    printf("no");
    }
    }
    int main()
    {
    int **m;
    int r;
    scanf("%d",&r);
    m=create(r,r);
    m=getelement(m,r,r);
    exec(m,r,r);
    return 0;
    }

    Saturday, 22 July 2017

    Top 100 Networking Interview Questions click here
    Basic Networking Interview Questions with answer  click here
    Top 500 Java Interview Questions and Answers click here

    Friday, 21 July 2017

    Write program for Lower Triangula Matrix

    Lower triangle matrix
    Write a program to print the following pattern for a given integer.

    Sample Input 1:
    3
    Sample Output 1:

    1
    6 2
    5 4 3 
                                              C-Solution
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    int main()
    {
    int n,i,c=1,j=0,ans;
    scanf("%d",&n);
    int a[n][n];
    if(n%2==0){ans=(pow(n,2)/2)+n/2;}
    else
    ans=(n-(n/2))*n;

    int m=n-1,p=0,l=0,k;
    while(c-1<ans)
    {
    for(i=l+p;i<=m&&c-1<ans;i++)
    a[i][i-l]=c++;
    ++l;
    for(j=m-l;j>=p&&c-1<ans;j--)
    a[m][j]=c++;
    for(k=m-1;k>l+p-1&&c-1<ans;k--)
    a[k][p]=c++;
    m--;p++;
    }
    for(i=0;i<n;i++)
    { for(j=0;j<=i;j++)
    { printf("%d ",a[i][j]);}
    printf("\n");
    }
    return 0;
    }

    Write a C program to print the elements of a square matrix in spiral order from the center.

                                                 Spiral Matrix 
    Assume the size of the matrix is odd.
    Sample Input:
    3
    1 2 3
    4 5 6
    7 8 9
    Sample Output:
    5 4 7 8 9 6 3 2 1 
                                                C-Solution
    #include<stdio.h>
    int main()
    {
    int n,i,j;
    scanf("%d",&n);int a[n][n],b[n*n],c=0;
    for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
    scanf("%d",&a[i][j]);//printf("%d ",a[i][j]);
    }
    }

    int top=0,bottom=n-1,left=0,right=n-1,direction=0;
    while(top<=bottom&&left<=right)
    {
    if(direction==0)
    {
    for(i=left;i<=right;i++){
    b[c]=a[top][i];c++;
    //printf("%d ",b[c-1]);
    }
    top++;
    }
    else if(direction==1)
    {
    for(i=top;i<=bottom;i++)
    {
    b[c]=a[i][right];c++;
    //printf("%d",b[c-1]);
    }
    right--;
    }
    else if(direction==2)
    {
    for(i=right;i>=left;i--)
    {
    b[c]=a[bottom][i];c++;
    // printf("%d",b[c-1]);
    }bottom--;
    }
    else if(direction==3)
    {
    for(i=bottom;i>=top;i--)
    {
    b[c]=a[i][left];c++;
    // printf("%d",b[c-1]);
    }left++;


    }
    direction=(direction+1)%4;

    }
    for(i=c-1;i>=0;i--)
    { printf("%d ",b[i]);
    }
    return 0;
    }

    Write a C program to print circular pattern for a given integer.

    Write a C program to print the following pattern for a given integer.
    Sample Input 1:
    4
    Sample Output 1:
    4444444
    4333334
    4322234
    4321234
    4322234
    4333334
    4444444

                                           C-Solution
    #include<stdio.h>
    #include<stdlib.h>
    int findmax(int a,int b)
    {
    if(a>b)return a;
        else return b;
    }
    int main()
    {
    int n,i,j;
    scanf("%d",&n);
    int m=(n*2)-1;
    for(i=0;i<m;i++)
    {
    for(j=0;j<m;j++)
    {
    printf("%d",1+findmax(abs(n-i-1),abs(n-j-1)));
    }printf("\n");
    }
    return 0;
    }

    Write a program to divide an array into 2 part such that the average of each part should be same.

    Divide an array
    Write a program to divide an array into 2 part such that the average of each part should be same.
    Assume that there is only one solution possible.
    [Note: Print the output in ascending order. Always the first element is in the first part of the array.]
     
    Sample Input:
    5
    3
    4
    2
    9
    6
    Sample Output:
    3 9

    2 4 6 

                                                C-Solution
    #include<stdio.h>
    int main()
    {
    int n,sum=0,i,j,t,t1;
    scanf("%d",&n);int a[n],k=0,b[n],c[n];
    for(i=0;i<n;i++)
    {scanf("%d",&a[i]);
    sum=sum+a[i];}
    sum=sum/2;
    t1=a[0];
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    if(a[i]>a[j])
    { t=a[i];a[i]=a[j];a[j]=t;}
    t=0;
    for(i=0;i<n;i++)
    {
    if(a[i]<=sum)
    {
    sum=sum-a[i];
    b[k++]=a[i];
    }
    else
    c[t++]=a[i];

    }
    for(i=0;i<k;i++)
    {
    for(j=0;j<k;j++)
    {
        if(b[i]<b[j])
        {sum=b[i];b[i]=b[j];b[j]=sum;}
     }
    }
    for(i=0;i<t;i++)
    {
    for(j=0;j<t;j++)
    {
         if(c[i]<c[j])
         {sum=c[i];c[i]=c[j];c[j]=sum;}
       }
    }
    int flag=0;
    for(i=0;i<k;i++)
    {  
     if(b[i]==t1)
    {flag=1;break;}
    }
    if(flag)
    {
    for(i=0;i<k;i++)
    printf("%d ",b[i]);printf("\n");
    for(i=0;i<t;i++)
    printf("%d ",c[i]);
    }
    else
    {
    for(i=0;i<t;i++)
    printf("%d ",c[i]);printf("\n");
    for(i=0;i<k;i++)
    printf("%d ",b[i]);
    }
    return 0;
    }



    Write a program to find the sum of the path which has the maximum length, given a square matrix.

    Maximum path sum
    Google is creating a toy robo can travel within a given square grid. Each cell in the grid has a number. To prove the intelligence of the company, Google decides to make the robo travel in a path which has the maximum sum when the number in the path are added.
    To start with, the project manager has asked the programmers to fix the source as coordinate (0,0) and destination as coordinate (n-1,n-1), where 'n' is the size of the square grid. And also the robo can travel in only two directions, right, down and diagonally right, i.e., if the current position is (x,y), the robo's next move can be either (x+1,y), (x,y+1) or (x+1,y+1).

    Write a program to find the sum of the path which has the maximum length, given a square matrix.
    Sample Input:
    4
    1 4 5 21
    3 22 1 5
    22 21 1 6
    3 32 2 2
    Sample Output:
    84
    Explanation for the sample input and output:
    This is the input matrix.
    1 4 5 21
    3 22 1 5
    22 21 1 6
    3 32 2 2
    This is the path with maximum sum.

                                                                    C-Solution
    #include<stdio.h>
    #include<stdlib.h>
    int max(int x, int y, int z);
    int maxSum(int cost[50][50], int m, int n)
    {
    if (n < 0 || m < 0)
    return 0;
    else if (m == 0 && n == 0)
    return cost[m][n];
    else
    return cost[m][n] +
     max(maxSum(cost,m-1,n-1),maxSum(cost,m-1,n),maxSum(cost,m,n-1));
    }

    int max(int x, int y, int z)
    {
    if (x > y)
    return (x > z)? x : z;
    else
    return (y > z)? y : z;
    }

    int main()
    {
    int n,i,j;
    scanf("%d",&n);int a[50][50];
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    scanf("%d",&a[i][j]);
    printf(" %d ", maxSum(a,n,n));
    return 0;
    }

    Sudoku --- Valid configuration or not

     Sudoku --- Valid configuration or not



    Sudoku is a popular single player game. The objective is to fill a 9x9 matrix with digits so that each column, each row, and all 9 non-overlapping 3x3 sub-matrices contain all of the digits from 1 through 9. Each 9x9 matrix is partially completed at the start of game play and typically has a unique solution.
    Given a completed NxN Sudoku matrix, your task is to determine whether it is a valid solution. A valid solution must satisfy the following criteria:
    • Each row contains each number from 1 to N, once each.
    • Each column contains each number from 1 to N, once each.
    • Divide the NxN matrix into N non-overlapping sqrt(N)xsqrt(N) sub-matrices. Each sub-matrix contains each number from 1 to N, once each.

    Write a program to just check if the given matrix is a valid sudoku solution.

    Sample Input 1:
    4
    1 2 3 4
    3 4 1 2
    2 1 4 3
    4 3 2 1

    Sample Output 1:

    yes
                                                   C - Solution
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    int n;
    int checkgrid(int **a,int row,int col,int check1,int sum)
    { int i,j;
    for(i=row;i<(row+sqrt(n));i++)
    for(j=col;j<(col+sqrt(n));j++)
    {
    if(!(a[i][j]>=1 && a[i][j]<=n)){return 1;}
    check1=check1+a[i][j];
    }
    if(sum!=check1)return 1;
    return 0;
    }
    int main()
    { int sum=0,check1=0,check2=0,flag=0,i,j;
    scanf("%d",&n);
    if(n%2==0) sum=(pow(n,2)/2)+(n/2);
    else sum=(n-(n/2))*n;
    int **a=(int**)malloc(sizeof(int*)*n);
    for(i=0;i<n;i++)a[i]=malloc(n*sizeof(int));
    for(i=0;i<n;i++)
    for(j=0;j<n;j++)
    scanf("%d",&a[i][j]);
    for(i=0;i<n;i++)
    { check1=0;check2=0;
    for(j=0;j<n;j++)
    {
    if(!(a[i][j]>=1&&a[i][j]<=n)){printf("no");
                     return 0;}
    check1+=a[i][j];check2+=a[j][i];
    }
    if(check1!=sum||check2!=sum) {flag=1;break;}
    }
    if(flag!=1)
    {
    for(i=0;i<n;i=i+sqrt(n))
    for(j=0;j<n;j=j+sqrt(n))
    {
    flag=checkgrid(a,i,j,0,sum);
                  if(flag){printf("no");return 0;}
    	         }
    }
    if(flag)printf("no");
    else printf("yes");
    return 0;
    }

    Sort the numbers based on the weight in decreasing order

    Number Weight
    Given a set of numbers like <10, 36, 54,89,12> write a program to find sum of weights based on the following conditions
        1. 5 if a perfect square
        2. 4 if multiple of 4 and divisible by 6
        3. 3 if even number


    Print the output as follows.
    (10,its_weight)(36,its weight)(89,its weight)

    Note: Sort the numbers based on the weight in decreasing order. If 2 weights are same, display the numbers based on increasing order.

    Sample Input:
    5
    10 36 54 89 12
    Sample Output:
    (36,12)(12,7)(10,3)(54,3)(89,0)


                                               C-Solution 
    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    int main()
    {
    int n,i,j,t1,t2;
    scanf("%d",&n);
    int *a=(int *)malloc(n*sizeof(int));
    int *b=(int *)calloc(n,sizeof(int));
    for(i=0;i<n;i++)
    {
    scanf("%d",&a[i]);
    }

    for(i=0;i<n;i++)
    {
    if(sqrt(a[i])*sqrt(a[i])==a[i])
    {
    b[i]+=5;
    }
    if(a[i]%4==0&&a[i]%6==0)
    {
    b[i]+=4;
    }
    if(a[i]%2==0)
    {
    b[i]+=3;
    }
    }
    for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
    if(b[i]<b[j])
    {
    t1=a[i];t2=b[i];
    a[i]=a[j];b[i]=b[j];
    a[j]=t1;b[j]=t2;
    }
    else if(b[i]==b[j])
    {
    t1=a[i];a[i]=a[j];a[j]=t1;
    }
    }
    }
    for(i=n-1;i>=0;i--)
    {
    printf("(%d,%d)",a[i],b[i]);
    }
    return 0;
    }

    ZOHO Interview Questions PDF Download

    ZOHO C Aptitude click here

    ZOHO 2nd Round Questions click here

    Wednesday, 19 July 2017

    Program to Find Number of Grandchildren - Zoho Programming Test Question

                               Grand Children
    Here we will see a c program to find number of grandchildren, great 
    grandchildren great-great grandchildren and so-on of a given person. In 
    this program, the input is a table with two columns, 'Child' and 'Father'.
    Then we enter a name whose number grandchildren, great grandchildren
    etc is to be calculated. We do not have to count children. An example is:
    Given a two dimensional array of strings like
    <”luke”, “shaw”>
    <”wayne”, “rooney”>
    <”rooney”, “ronaldo”>
    <”shaw”, “rooney”>
    Where in each row, the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren. Here “ronaldo” has total 3 grandchildren (2 grandchildren: wayne and shaw ; 
    a great grandchild luke). So our output should be 3.
    write a program to find the number of grandchilden for a given name.
                                              C - Solution
    #include<stdio.h>
    #include<string.h>
    int n;
    char name[20];

    struct reln{
    char child[20];
    char father[20];
    }r[10];

    int count=0;
    void countChildren(char name[])
        {
        int j;
        for(j=0;j<n;j++)
            {
            if(strcmp(name,r[j].father)==0)
                {
                count++;
                countChildren(r[j].child);
                }
            }
        }

    void main()
    {
    int i;
    printf("\nEnter the number of inputs: ");
    scanf("%d",&n);
    for(i=0;i<n;i++)
        {
        scanf("%s",r[i].child);
        scanf("%s",r[i].father);
        }
    printf("\nEnter name of the one whose no. of grandchildren 
    is needed: ");
    scanf("%s",name);
    for(i=0;i<n;i++)
        {
        if(strcmp(r[i].father,name)==0)
            countChildren(r[i].child);
        }
    printf("\nNo .of grandchildren of %s=%d",name,count);
    }
                                          JAVA - Solution
    import java.util.Scanner;
    import java.util.ArrayList;
    class Main {
    public static void main(String args[]) {
    Scanner scan=new Scanner(System.in);
    int n=scan.nextInt();scan.nextLine();
    ArrayList< String > arr=new ArrayList<>();
    int i,j,flag;
    String[] input=new String[n];
    String[] father=new String[n];
    String[] child=new String[n];
    for(i=0;i<n;i++)
    {
    input[i]=scan.nextLine();
    father[i]="";
    child[i]="";
    flag=0;
    for(j=0;j<input[i].length();j++)
    {
    if(input[i].charAt(j)==',')flag=1;
    if(((input[i].charAt(j)>='a'&&input[i].charAt(j)<='z')||
        (input[i].charAt(j)>='A' && input[i].charAt(j)<='Z'))&&flag==0)
    child[i]=child[i]+input[i].charAt(j);
    else if(((input[i].charAt(j)>='a'&&input[i].charAt(j)<='z')||
        (input[i].charAt(j)>='A'&&input[i].charAt(j)<='Z'))&&flag==1)
    father[i]=father[i]+input[i].charAt(j);
    }
    }
    String search=scan.nextLine();
    for(i=0;i<n;i++)
    {
    if(father[i].equals(search))
    {
    arr.add(child[i]);
    }
    }
    flag=0;
    for(i=0;i<arr.size();i++)
      {
    for(j=0;j<n;j++)
    {
    if(father[j].equals(arr.get(i))) 
            flag++;   
    }
    }
    System.out.println(flag);
     
     }
    }
     
     Sample Input:
    4
    <”luke”, “shaw”>
    <”wayne”, “rooney”>
    <”rooney”, “ronaldo”>
    <”shaw”, “rooney”>
    ronaldo

    Sample Output:
    2

    Home Page

     Zoho Interview Questions Alternate Sorting   C program for Circular Pattern C program for Spiral Matrix C program to print ...