Interview Question


Country: India




Comment hidden because of low score. Click to expand.
1
of 3 vote

46=32+8+4+2

n<<5 + n<<3 + n<<2 + n<<1

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

this should be the way to perform multiplication, but what about division?

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

If you have a multiplication operator, you can use binary search in conjunction with multiplication to search for the quotient. Not necessarily the most efficient way though.

- eugene.yarovoi August 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
int main()
{
int i,output=0,mask=1,min,max;
printf("enter two no.'s);
scanf("%d%d",&min,&max);
if(min>max)
{
i=min;
min=max;
max=i;
}
for(i=1;mask<=min;i++,mask=mask*2,max<<=1) if(min&mask) output+=max;
printf("%d",output);
}



//Complexity= no. of bits in lesser number

- dilip kasana August 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

does multiply only not divide probably ..

- nk August 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can do the multiplication using adding but the division by subtracting.
if the number will be the multiple of 2 the we can divide by the right shift of bit of number which will be divided .

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

46 => (101110)

m * (2^5 + 2^3 + 2^2 + 2^1)

=> m * 2^5 + m * 2^3 + m * 2^2 + m * 2
=> m << 5 + m << 3 + m << 2 + m << 1

- Yev August 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

You can do it with ONLY adding. Just add the number to itself 46 times.

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

what if the number is big... say 1024, the complexity increases ?
Using bit shift operator it is shift 10 bits left.

- nk August 01, 2012 | Flag


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