Goldman Sachs Interview Question for Analysts






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

#include<stdio.h>
#include<malloc.h>
struct node
{

int value;
struct node *right;
struct node *left;

};
typedef struct node mynode;
mynode *root;

void add_node(int);
void levelOrderTraversal(mynode *);

int main(int argc, char* argv[])

{
root = NULL;
add_node(5);
add_node(1);
add_node(-20);
add_node(10);
add_node(23);
add_node(67);
add_node(13);
printf("\n\n\nLEVEL ORDER TRAVERSAL\n\n");
levelOrderTraversal(root);

}
// Function to add a new node...

void add_node(int value)
{
mynode *prev, *cur, *temp;
temp=(mynode *) malloc(sizeof(mynode));
temp->value = value;
temp->right = NULL;
temp->left = NULL;
if(root==NULL)
{
printf("\nCreating the root..\n");
root = temp;
return;
}
prev=NULL;
cur=root;
while(cur!=NULL)
{
prev=cur;
cur=(value<=root->value)?cur->left:cur->right;

}
if(value < prev->value)
prev->left=temp;

else
prev->right=temp;

}
// Level order traversal..

void levelOrderTraversal(mynode *root)
{
mynode *queue[100] = {(mynode *)0}; // Important to initialize!
int size = 0;
int queue_pointer = 0;
while(root)
{
printf("[%d] ", root->value);
if(root->left)
{
queue[size++] = root->left;
}
if(root->right)
{
queue[size++] = root->right;
}
root = queue[queue_pointer++];

}

}

- Anonymous January 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Unbelievable easy questions!!!!!!Is that so easy to enter GS, or the difficulty is to get an interview?

Compare the questions composed by MS, or G, or A, these are just pieces of cake......

- Anonymous January 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Is this an onsite question? What kind of questions do they ask for phone interviews?

- anonymous January 31, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//while(cur!=NULL)
//{
//prev=cur;
//cur=(value<=root->value)?cur->left:cur->right;
//}
i think the 3rd line in the above snippet from the written code should have been cur->value instead of root->value

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

I think in the line
root = queue[queue_pointer++]
queue_pointer++ needs to be replaced with ++queue_pointer.

- Anonymous April 15, 2011 | 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