Bloomberg LP Interview Question for Financial Software Developers


Country: United States
Interview Type: Phone Interview




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

struct node{
    int info;
    struct node *leftch;
    struct node *rightch;
};


int AppendInBST(struct node **start, int num)
{
    struct node *ptr,*tmp,*par=NULL;
    tmp = (struct node*)malloc(sizeof(struct node));
    tmp->info = num;
    tmp->leftch= NULL;
    tmp->rightch = NULL;

    ptr = *start;
    while(ptr != NULL)
    {
        par = ptr;
        if(num > ptr->info)
            ptr = ptr->rightch;
        else if(num < ptr->info)
            ptr = ptr->leftch;
        else{
            printf("Duplicate Entry\n");
            return 0;
        }
    }
    if(par == NULL)
    {
        *start = tmp;
    }
    else if(par->info > num)
        par->leftch= tmp;
    else if((par->info) < num)
        par->rightch = tmp;
    return 1;
}

- Amit Khatri August 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this one? Since once mention the Btree I always think of recursive

struct node{
    int data;
    node *leftch;
    node *rightch;
    };
    
    void intoatree(struct node **root, int n){
        node *temp=new node; 
        (*temp).data=n;
        (*temp).leftch=NULL;
        (*temp).rightch=NULL;
        
        node **par;
        
        par=root;
    
        
        if(*root==NULL){
            *root=temp; //insert as the first node
        }
        else if((*(*par)).data==n){
            cout<<"duplicate input"<<endl;
            return;
        }
        else if((*(*par)).data>n){
            *par=(*(*par)).leftch;
            intoatree(par,n);
        }
        else{
            *par=(*(*par)).rightch;
            intoatree(par,n);
        }
        
    }

- code.cracker1991 December 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about this?

TreeNode* insertNode(TreeNode *root, TreeNode *newNode) {
	if (root == NULL) {
		// if there is no root, use current one as root
		return newNode;
	}

	if (newNode->val >= root->val) {
		root->right = insertNode(root->right, newNode);
	} else {
		root->left = insertNode(root->left, newNode);
	}
	return root;
}

- Anonymous February 04, 2015 | 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