Imagination Technologies Interview Question for Graphics Programmers


Country: India
Interview Type: Phone Interview




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

Simply swap the first occurrence of the 01 pair or 10 pair, and you will reach a step up or step down integer. Code should look something like:

int NextInt(int n)
{
    int mask = 0x02;
    int bit = n & 0x01;
    while (mask < n)
    {
        if (n & mask != bit)
        {
            break;
        }
        mask = mask << 1;
    }

    if (bit == 1)
    {
        n |= mask;
        n &= (mask >> 1) ^ 0xFFFFFFFF;
    }
    else
    {
        n &= (mask ^ 0xFFFFFFFF);
        n |= (mask >> 1);
    }
}

- Anonymous August 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

that is the correct answer:
swap the first occurence of 01 with 10 for the next higher
swap the first occurence of 10 with 01 for the next lower
while taking into account the max int and lowest boundary conditions.

- yemre_ankara August 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@yemre_ankara ....just swapping first occurence of 01 with 10 won't give you the immediate next heighest number for ex consider 12 ( 1100 )...with what you say the next heighest number will be (10100) i.e 20 but the next heighest integer is 17 i.e (10001)

- Anonymous September 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

for(int i = n-1 ; i >= -n ; i--){
if( length == CountNumberOfOnes(i)){
cout << "Lower value with same number of 0's :" << i << endl;
break;
}
}

for(int i = n+1 ; i <= (n*10) ; i++){
if( length == CountNumberOfOnes(i)){
cout << "Higher value with same number of 0's :" << i << endl;
break;
}
}

- Anonymous August 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In your above code, if we take n=0 then what will happen??

- Aditya January 01, 2015 | 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