## 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

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

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

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

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.

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

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

//Complexity= no. of bits in lesser number

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

does multiply only not divide probably ..

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 .

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

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.

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

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

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.

### 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.