## CareerCup Interview Question for Accountants

Country: India
Interview Type: In-Person

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

``````int mult2(int a, int b)
{
if (b == 0)
return 0;

bool negative = false;

if (b < 0) {
negative = true;
b = -b;
}

int res = 0;

for (int i = 0; b && i < 32; i++) {
if (b & 1)
res += a << i;
b >>= 1;
}

return negative ? -res : res;
}``````

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

Nice!

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

assumes b >= 0

a*b = (a+a+ .. + a) <-- add 'a' to itself b times (with a loop)

if b<0, do above loop (-b) times then negate result

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

That is not vedic.

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

I am from the Vedic bloodline, and I came up with above, thus that is Vedic :)

If there is another Vedic multiplication method, then whoever asks me to do this will have to explain how that works, and then I'll translate their psuedocode to code line for line :P

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

NO HIRE.

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

It's unfortunate that I don't qualify for Random Idiot Inc. ^^^^

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

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

Didn't mean to post this,
but try for also multiplying large numbers more than 2^64

And upvote the question :)

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

``````private static int multipliy(int i, int j) {
int result = 0;

while (j > 0) {
if ((j % 2) != 0) {
result += i;
}

i = i << 1; //Doubles i
j = j >> 1; // Halves j
}

return result;
}``````

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.