AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: kopi — October 6, 2006
    -16 votes
      + -

    #include <stdio.h>

    int main()
    {
    int a[10]={1, 2, 4, 4, 7, 8, 9, 14, 14, 20};
    int i;

    for (i = 0;i<10;i++)
    {
    if (a[i] != a[i+1])
    printf(”%dn”,a[i]);
    }
    return 0;
    }

  2. Submitted By: guest — October 6, 2006
    +1 votes
      + -

    #include <stdio.h>

    main()
    {
    int a[10] = {0,4,4,4,5,6,6,8,9,9};
    int i;

    for(i=0; i<10; i++)
    {
    if(a[i] == a[i+1] )
    {
    while(a[i] == a[i+1]) i++;
    }
    else
    printf(”%d “, a[i]);

    }
    printf(”n”);
    }

  3. Submitted By: Ant — October 17, 2006
    +12 votes
      + -

    Guys, you both will get an error when i = 9

    if(a[9] == a[10]) ….

  4. Submitted By: pKolluri — November 17, 2006
    +15 votes
      + -

    Guys look at this solution:

    int arr[22] = new int[] { 1, 2, 4, 4, 4,4,4,4,4,7, 8, 9,14,14,14,14,14,14, 14, 14 ,40};
    int i;
    for(i=0;i

  5. Submitted By: helper — December 6, 2006
    +0 votes
      + -

    oid YankDup(int a[],int len)
    {
    int i;
    printf(”(%d, “,a[0]);
    for (i = 1; i

  6. Submitted By: jijiduru — March 8, 2007
    +3 votes
      + -

    You’re all kinda wrong.
    Don’t you consider the case when lenght(a)=1?

  7. Submitted By: krish — April 7, 2007
    +6 votes
      + -

    //takes array of elements and size of the array as inputs
    //returns new array with dups removed and the newSize of //the ayyay
    int compact(int n,arrar a)
    {
    int curr = 0;
    int next=0;
    int newSize = n;

    next = curr+1;

    while(next

  8. Submitted By: Septembersun — April 22, 2007
    +0 votes
      + -

    How good would this be?
    As you traverse through the elements in the list, form a binary search tree out of the elements in the list. As you go to each new element, search for the element in the tree. If found, proceed to the next element in the list. Else, insert the element into the tree before moving to the next element.

  9. Submitted By: Septembersun — April 22, 2007
    not yet rated
      + -

    Oh sorry, that approach wouldnt be much efficient. We should be making use of the fact that the list at hand is sorted.

  10. Submitted By: MaverickUTA — April 23, 2007
    +3 votes
      + -

    1,3,3,5,7,7,7,8,8,9
    1,3,5,7,8,9

    int *newlist(int *arr,int size)
    {
    int upper,lower=0;
    for(int upper=1;upper

  11. Submitted By: cc — April 26, 2007
    -1 votes
      + -

    void remove_dup(list &l)
    {
    if ( l.size() > 1 ) {
    list::iterator first = l.begin();
    ++first;
    for ( list::iterator second = l.begin();
    first != l.end(); ) {
    if ( *second == *first ) {
    first = l.erase( first );
    }
    else {
    ++first;
    ++second;
    }
    }
    }
    }

  12. Submitted By: MHM — May 22, 2007
    not yet rated
      + -

    void main(void)
    {
    int const arraySize = 21;
    int arr[arraySize] = { 1, 2, 4, 4, 4,4,4,4,4,7, 8, 9,14,14,14,14,14,14, 14, 14 ,40};
    int current = 0;
    int last = 1;

    while (last

  13. Submitted By: Jeff — May 23, 2007
    not yet rated
      + -

    int a[] = { 1,2,3,3,4,5,5,5,6,6,7,7,7,7,8,10,10,11,12,15,16,17,17,20};

    int current = a[0];
    bool dup = false;
    int size = sizeof(a) / sizeof(int);

    for(int i = 0; i

  14. Submitted By: Shashi — June 13, 2007
    not yet rated
      + -

    The code published earlier fails when the repeating elements of the array are not adjacent to each other or are scattered across the array.
    In such a case the possible solution is do in place sorting of the array and ignore the adjacent repeating elements.

    Here’s the code:-

    #include
    #include

    void insort(int *,int);

    int main(void)
    {
    int a[10]={20,7,4,2,8,9,14,4,14,1};
    int i;

    insort(a,10);

    for (i=0;i=0)&&(arr[i]>key))
    {
    arr[i+1]=arr[i];
    i = i-1;
    }
    arr[i+1] = key;
    }
    }

  15. Submitted By: Anand (pythonhacker) — February 5, 2008
    +1 votes
      + -

    A binary search tree can be used here. Extract every element from the array and insert into a BST if not already there.

    Another option is to again use the excellent bitmap data structure. Here is the algorithm.

    1. Initialize a bitmap data structure to maximum value in the array (last entry) + 1. Set all entries to zero.
    2. Loop through the array. Turn on the bit at the index of the array element to 1.
    3. Loop through the bitmap and print out all the bit indices which are 1. There you are.

    Here is the code.

    def nodups(l):

    newl = []
    # Using a bitmap
    bitmap = [0]*(l[-1]+1)
    for num in l:
    bitmap[num] = 1

    for x in range(len(bitmap)):
    if bitmap[x]==1:
    newl.append(x)

    return newl

    print nodups([1,2,3,3,4,5,5,5,6,6,7,7,7,7,8,10,10,11,12,15,16,17,17,20])

  16. Submitted By: Sunny arora — June 7, 2008
    +1 votes
      + -

    #include
    /* Here is my code */

    int main()
    {
    int a[10] = {1,2,2,3,4,5,5,6,7,7};
    int i,t;
    int b[10];
    t = a[0];
    printf(”%d\t”,t);
    for ( i = 1;i

  17. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.