Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Question is not clear. Please, give an example.

- fiddler.g July 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we have numbers from 1-100 unsorted in an array
let say some numbers are missing from it. We have to find them.

- DashDash July 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't think it can be done with constant memory independent of n and k.

- ftfish July 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wrong, you just have to modify the input.

- Anonymous July 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

1. If he is wrong prove it! :)
2. He/she is not wrong because you cannot keep k numbers in 3 vars if k > 3.

- S July 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can get number of elements i.e. value of K using the input constraints.
The three varaibles will be Min, Max and Length for the Array which can all computed in a single parse i.e. O(n).
So value of K = (Max-Min)-Lenght.

Still what this K elements are is a mystery spot!!!

- Kicks July 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can get number of elements i.e. value of K using the input constraints.
The three varaibles will be Min, Max and Length for the Array which can all computed in a single parse i.e. O(n).
So value of K = (Max-Min)-Lenght.

Still what this K elements are is a mystery spot!!!

- KicksS July 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the code that takes care of duplicates as well. Complexity O(n). If swap() is done inline, it will take only 1 extra space (int tmp). Plus 1 for 'int i' and plus 1 for 'int size'. So not more than 3 variable used. :-)

#include <stdio.h>

void swap(int *a, int *b)
{
    int tmp = *a; *a = *b; *b = tmp;
}

void find_missing(int *a, int size)
{
    int i = 0;
    for (i=1; i<=size; i++) {
        while (a[i-1] != -1 && a[i-1] != i && a[a[i-1]-1] != a[i-1]) {
            swap(&a[i-1], &a[a[i-1]-1]);
        }
    }

    for (i=0; i<size; i++)
        if (a[i] != i+1)
            printf("%d ", i+1);
}

int main()
{
    #define SIZE 12
    /* array with enough space for n elements
       extra space padded with -1*/
    int a[SIZE] = {6,4,9,4,5,8,3,11,-1,-1,-1,-1};
    find_missing(a, SIZE);
}

- jtr.hkcr March 10, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More