VMWare Inc Interview Question for Member Technical Staffs


Country: United States
Interview Type: Phone Interview




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

The "find for each set bit its index" does not make much sense given this function declaration. A first approach could be

int find_set_bits(uint8 *from, int size) {
    int result = 0;
    for (int i = 0 ; i < size; i++) {
        for (int j = 0; j < 8; j++) {
            if (*from & (1<< j )) {
                result++;
                // save the indices?
            }
        }
        from++;
    }
    return result;
}

For counting the number of set bits, we should use a lookup table. Again, this can be extended to get the indices, but it doesn't match the function declaration.

const int TABLE_SIZE = 1 << 8;
uint8 set_bits_table[TABLE_SIZE];
void preprocess() {
    int i , j;
    for (i = 0 ; i < TABLE_SIZE; i++) {
         set_bits_table[i] = 0;
         for (j = 0 ; j < 8 ; j++) {
              if ( i & (1 << j )) {
                  set_bits_table[i]++;
              }
         }
    }
}
int find_set_bits(uint8 *from, int size) {
    int result = 0;
    for (int i = 0 ; i < size; i++) {
        result += set_bits_table[*from];
        from++;
    }
    return result;
}

- Miguel Oliveira July 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think you can form a linked list or some data structure wherein every entry can store the information about the starting point of the index and the runlength.

- PJ August 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

int main()
{
	int n=138;
	int *t=new int[8];
	int cnt=0,k=0;
	memset(t,0,sizeof(int)*8);
	while(n!=0)
	{
		if(n&1==1)
		{
			cnt++;
			t[k]=1;
		}
		k++;
		n=n>>1;
	}

	for(int i=0;i<8;i++)
		if(t[i]==1)
			printf("%d\n",i);
	printf("\n-------- %d\n",cnt);
	delete [] t;

	return 1;
}

- Anonymous July 24, 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