Bloomberg LP Interview Question for Software Engineer / Developers






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

http://en.wikipedia.org/wiki/Karatsuba_algorithm

- K January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

could anyone provide sample answers to this?

- recentKid March 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

could anyone please share sample answer to this problem?

- recentKid March 11, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the trick is that the number could be over 16 byte
so first find out how many bytes we need, then multiply different parts seperately

- J.C. April 01, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

represent numbers using linked list ...having 16 bype per node and hten multiply it...answer would be again number in linked list..

- muks May 07, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

basic math
karatsuba

- ani August 26, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

accept the input as strings...note that 2224+3443 is the same as 43+24 (subproblem one) and 22+34 (sub problem two.)..use self recursion and send the "carry " with a static variable. I coded it and it worked..cant seem to find it now.


The program will accept the strings..example "3294894395883045890803849059348" and parse them into smaller blocks store them in ints and use the method suggested

- Anupam December 27, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is multiplication, not addition.

- BU September 24, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Try Russian peasant algorithm

- jai January 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess linked list soln is a good one.

- Java Coder January 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ans this some1

- Anonymous October 04, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about using the regular hand-written approach, like with pen and paper, eventually reducing it to a series of single digit additions and carry management.

- wizardry November 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this:

int main(){
int a = 9, b = 12;
int result = 0;
while (b&01){
if(b!=0) result += a;

a <<= 1;
b >>= 1;
}
}

- SID November 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

faster algorithm would be
a >>=1;
b <<=1;

;) This is the russian peasant algorithm somebody mentioned

- wihenao August 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If Peasant multiplication, code should be
int main(){
int a = 9, b = 12;
int result = 0;
while (b){
if(b&01) result += a;
a <<= 1;
b >>= 1;
}
}

- Anonymous March 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

An Algorithm for multiplication of long numbers is given in TH Cormen. It basically uses FFT to multiply long numbers. Resulting algorithm multiplies in nlogn multiplications instead of n^2

- Anonymous March 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

An Algorithm for multiplication of long numbers is given in TH Cormen. It basically uses FFT to multiply long numbers. Resulting algorithm multiplies in nlogn multiplications instead of n^2

- Sachin March 05, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a <<= 1

- wihenao August 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define MAX 40                   
main()
{
    int Num[2][MAX];         
    int Result[MAX];         
    int Index[2]={0,0};      
    int i,j,k;
    int data;
    int tmp1,tmp2;         
    int Flag;

/**********************************************************/
    for(tmp1=0;tmp1<MAX;tmp1++)
    {
        Num[0][tmp1]=0;
        Num[1][tmp1]=0;
        Result[tmp1]=0;
    }

/*******************************************************/
    for(tmp1=0;tmp1<2;tmp1++)
    {
        printf("input number");
        scanf("%d",&data);
        while((data>=0)&&(data<10))
        {
            Num[tmp1][Index[tmp1]]=data;
            Index[tmp1]++;
            scanf("%d",&data);
        }
        printf("%d:",tmp1+1);
        for(tmp2=0;tmp2<Index[tmp1];tmp2++)
        {
            printf("%d",Num[tmp1][tmp2]);
        }
        printf("\n");
    }

/************************************************************/
    tmp1=MAX-1;
    for(i=(Index[1]-1);i>-1;i--)
    {   
        k=tmp1;                         
        for(j=(Index[0]-1);j>-1;j--)
        {    Flag=1;
            Result[k]+=Num[0][j]*Num[1][i];
            if(Result[k]>=10)       
            {
                Result[k-1]+=Result[k]/10;
                Result[k]=Result[k]%10;
                Flag=0;         
            }
            k--;
        }
        tmp1--;
    }

/**************************************************************/
     for(tmp1=(k+Flag);tmp1<MAX;tmp1++)
    {
        printf("%d",Result[tmp1]);
    }
    printf("\n");

}

- Anonymous September 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This one works.

void multiply(char *str1, char *str2, char **result)
{
   int aLen = strlen(str1);
   int bLen = strlen(str2);
   int rLen = aLen + bLen;
   *result = (char *)malloc(rLen+1);
   int i,j;
   for (i = 0; i < rLen; i++)
      (*result)[i] = '0';
   (*result)[rLen] = '\0';
   
   char *a = (char *)malloc(aLen);
   for (i = 0; i < aLen; i++)
      a[i] = str1[aLen-i-1];
   char *b = (char *)malloc(bLen);
   for (i = 0; i < bLen; i++)
      b[i] = str2[bLen-i-1];
   
   for (i = 0; i < aLen; i++)
   {
      for (j = 0; j < bLen; j++)
      {
         (*result)[i+j] += (a[i]-'0')*(b[j]-'0');
         int k = 1;
         int temp = (*result)[i+j]-'0';
         if (temp >= 10)
         {
            (*result)[i+j] = temp % 10 +'0';
            (*result)[i+j+k] += temp / 10;
            temp = (*result)[i+j+k] -'0';
            k++;
         }
      }
   }
   i = rLen -1;
   while ((*result)[i] == '0')
      i--;
   rLen = i+1;
   (*result)[rLen] = '\0';
   for (i = 0; i < rLen/2; i++)
   {
      char c;
      c = (*result)[i];
      (*result)[i] = (*result)[rLen-i-1];
      (*result)[rLen-i-1] = c;
   }
   free(a);
   free(b);
}

- Ying February 19, 2010 | 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