Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

string  sumv( vector<vector<int>> &ans)
{
    vector<int> res;
    int pos = 0;
    int carry=0;
    for ( int col = 0; col < ans[ans.size()-1].size(); col++ )
    {
        int sum = carry;
        for ( vector<int>& row: ans )
        {
            if ( col < row.size() )
                sum+=row[col];
        }
        
        if ( col == res.size() )
            res.push_back(0);
        else
           sum+=res[col];
        
        if ( sum > 9 )
        {
            carry=sum/10;
            sum=sum%10;
        }
        else
            carry=0;
        
        res[col] = sum;
    }
    string str;
    for_each(res.rbegin(), res.rend(),[&](int & i)
             {
                 str.append(1,(i+'0'));
             });

    return str;
}

void Product(string s1, string s2)
{
    int offset=0;
    vector<vector<int>> ans;
    for ( char cd: s2)
    {
        vector<int> prod;
        for ( int i=0; i <offset;i++)
            prod.push_back(0);
        
        int carry = 0;
        for ( char cc: s1)
        {
            int pr = ((cd-'0')*(cc-'0'))+carry;
      
            if (( pr ) > 9 )
            {
                prod.push_back(pr%10);
                carry=pr/10;
            }
            else
                prod.push_back(pr);
        }
        if ( carry )
            prod.push_back(carry);
        for_each(prod.begin(), prod.end(),[](int i ) { cout << i <<" ";} );
        cout<<endl;
        ans.push_back(prod);
        offset++;
    }
    string res = sumv(ans);
    unsigned long long verylong = ((unsigned long long)(atoll(s1.c_str())*atoll(s2.c_str())));
    cout << res << " " << verylong << endl;
}

- drolmal April 07, 2017 | 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