Tuesday, January 26, 2016

bloomberg phone interview questions

// This is the text editor interface.
// Anything you type or change here will be seen by the other person in real time.
1 -> 2 -> 3  123
4 -> 5 -> 6  456
struct ListNode
{
    int val;
    ListNode *next;
    ListNode (int _val):val(_val),next(NULL){};
}
ListNode *reverse(ListNode *A)
{
    ListNode *pre =NULL;
    ListNode *curr = A;
    ListNode *next;
    while(curr)
    {
        next = curr->next;
        curr->next = pre;
        pre = curr;
        curr = next;
    }
    return pre;
}


ListNode * addTwoNumbers(ListNode *_A,ListNode *_B)
{
    int carry = 0;
    ListNode dummy(0);
    ListNode *p = &dummy;
   
    ListNode *A = reverse(_A);
    ListNode *B = reverse(_B);
   
    while(A||B)
    {
        int a = A!=NULL?A->val:0;
        int b = B!=NULL?B->val:0;
        carry = (a+b+carry)/10; a = 3, b = 5, carry = 0
        int c = (a+b+carry)%10;
        p->next = new ListNode(c);
        p = p->next;
        A = A->next;
        B = B->next;
    }
    if(carry)
        p->next = new ListNode(carry);
    return dummy.next;
}


AAPL 50
MSFT 100
GOGL 75

new trade IBM 200
IBM 200
AAPL 50
MSFT 100

new trade AAPL 100
AAPL 100
IBM 200
MSFT 100
list mycompanylist;
list::iterator it;//tracking the position for the company in the list
unordered_map::iterator> mycompanymap;

No comments: