Monday, December 24, 2012

Cisco Interview Questions

Had 5 rounds of interview

1. Telephonic technical Round
    * steps of compilation
    * storage classes & memory allocation
    * pass by value & pass by reference
    * questions on pointers
    * stack & heap in C
    * Reverse a linked list
    * Middle element of a linked list
    * difference between insertion & quick sort
    * time complexities of all sorting algorithms
    * difference between TCP & UDP

2. Technical round-1 (F2F)
    * TCP/IP layer
    * how ping works
    * IP header
    * questions about data link layer

3. Technical round-2 (F2F)
    * Find a duplicate in an array of 1 to n elements
    * swap without comparison
    * deletion of a linked list
    * find a loop in a linked list
    * set a bit in a integer
    * stack & heap - malloc & calloc
    * some questions in pointers

4. Technical round-3 (F2F)
    * find the sum of array using recursion
    * pattern matching
    * find the intersection of two linked list and questions on projects done.

5. Manager round (F2F)
    * how trace route works
    * how route works
    * ipconfig works
    * some HR questions like , how you manage pressure, strength etc.,

Monday, November 12, 2012

Implement atoi function


#include<stdio.h>
main()
{
// Declarations
    char str[100];
    int i,n,sign;
// Initializations
    i=0;
    n=0;
    scanf("%s",str);
// First string can be '+','-','tab','space','newline',numbers
    if((str[0]!='+') && (str[0]!='-') && (str[0]!='\t') && (str[0]!='\n') && (str[i]==' '))
    {
    if((str[0]<'0') || (str[0]>'9'))
    {
        return ;
    }       
    }
    else
    {
    // Getting the sign value
    sign=(str[0]=='-')?-1:1;
    if((str[i]=='+') || (str[i]=='-') || (str[i]=='\n') || (str[i]=='\t') || (str[i]==' '))
    i++;
   
    // Converting string to integer
    while(str[i]>='0' && str[i]<='9')
    {
        n=n*10+(str[i]-'0');
        i++;
    }
   
    n=n*sign;
    printf("%d",n);
    }           
}

Monday, October 1, 2012

Merging of two sorted arrays

 

Given two sorted arrays A & B where size of A is m & size of B is m+n .  B contains only n number of elements & m empty positions. Sorting should not take any extra memory.

#include<stdio.h>
main()
{
int A[]={1,3,7,10};
int B[7]={2,4,11};
int size_A;
int size_B;
int i;
size_A=sizeof(A)/sizeof(int);
size_B=sizeof(B)/sizeof(int);
size_A--;
size_B--;
int s=size_B;
int B_Elements= (size_B - size_A);
B_Elements--;

while((size_A >=0) && (B_Elements >=0))
{
if( (A[size_A] ) >= (B[B_Elements])){
        B[size_B]=A[size_A];

        printf("\n%d > = %d",A[size_A ] , B[B_Elements ]);
        size_A--;
        size_B--;
}
else
{
printf("\n%d < = %d",A[size_A ] , B[B_Elements ]);
B[size_B] = B[B_Elements];
size_B--;
B_Elements--;
}
}

if ( size_A >=0 ){
    while ( size_A >= 0 ){
B[size_B] = A[size_A];
size_A--;
size_B--;
    }
}
else if ( B_Elements >=0 ) {
    while (B_Elements >=0){
B[size_B] = B[size_B];
    B_Elements--;
    size_B--;
    }
}
else {
printf("Merging done");
}
printf("\n");
for(i=0;i<=s;i++)
printf("%d  ",B[i]);
}

Permutation of a given string


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void swap(char *x , char *y)
{
    char temp;
    temp=*x;
    *x=*y;
    *y=temp;
}
void do_permute(char *a, int start , int size)
{
    int itr;
    if ( start == size ){
        printf("%s\n",a);
    }
    else{
        for(itr=start;itr<size;itr++)
        {
            swap((a+start),(a+itr));
            do_permute(a,start+1,size);
            swap((a+start),(a+itr));
        }
    }
}
main()
{
    printf("PERMUTATION\n");
    char a[100];
    int size;
    scanf("%s",a);
    size=strlen(a);
    do_permute(a,0,size);
}

Sunday, September 30, 2012

Kadane’s Algorithm

 

public class kadane {
    public static void main(String args[])
    {
            System.out.println("Kadane Algorithm");
           
            int A[]={-2, -3, 4, -1, -2, 1, 5, -3};
            int max , max_final , i;
            max=max_final=0;
            int size=A.length;
            for(i=0;i<size;i++)
            {
                max=max+A[i];
                if(max < 0)
                    max=0;
               
                if(max_final<max)
                    max_final=max;
                           
            }
            System.out.println("Maximum sum : "+max_final);
    }
}

Output:

Maximum sum : 7

Some of the interview questions asked recently

 

1. Given a binary tree & a sum value. Find the two nodes in a binary tree whose sum is equal to the given sum.

2. Print all the permutations of a string.

3. Detect and remove the loop in linked list.

4. Given a binary tree , find the maximum rooted subtree (whose sum of its child is greater than other sub trees).

5. Difference between abstract class & packages in Java.

6. Convert Binary Search Tree to Sorted Doubly linked list.

7. Maximum circular subarry sum.

8. Given 3 numbers. Find the lease valid date formed by those numbers.

eg: 1,2 ,3. Output should be : 3/2/1. Note: should take care of cases like valid month & date & leap year.

9. Given binary tree . Print the sum of all the leaf nodes.

10. Given two sorted arrays , ‘A’ of size m and ‘B’ of size n+m. Array B will contain numbers in n positions and ‘m’ empty positions. Merget two Arrays. Note: Should not use extra memory.