Goldman Sachs Interview Question for Software Engineer / Developers


Country: United States




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

#include<stdio.h>
#include<stdlib.h>
#include <string>
using namespace std;

class employee
{
	int ID;
	string LName;
	string FName;
	employee* M;
	employee* Sub;

public:
	employee():ID(-1),LName(NULL),FName(NULL),M(NULL),Sub(NULL)
	{
		;
	}
	employee(int n,string fn,string ln,employee* manager=NULL,employee* subor=NULL)
	{
		ID = n;
		LName = ln;
		FName = fn;
		M = manager;
		Sub = subor;
	}
	void set_sub(employee * s)
	{
		this->Sub = s;
	}
	void Print_Infor()
	{
		printf("\n%d\n",this->ID);
	}
	employee * get_sub()
	{
		return this->Sub;
	}
	void get_subor()
	{
		this->Print_Infor();
		employee* p;
		for(p=this;p->get_sub()!=NULL;)
		{
			p=this->get_sub();
			p->Print_Infor();
		}
	}
};

int main()
{
	employee b(1,"hua","jun");
	employee VP(2,"He","pin",&b);
	b.set_sub(&VP);
	b.get_subor();
	getchar();
}

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

Assumption - An employee can report to only 1 manager
It can be implemented as a tree
P = Immediate Parent (Immediate manager)
R = Root of the tree (main boss)
E = Employee to search or add
P searchChildElementInTree(R ,E) - gives manager of the employee
R addEmployeeInTree(R, P, E) - assuming employee can have maximum of 5 immediate subordinates
displayTreeWithRootAs(P) - all nodes under P and its children should be displayed

- bitflipper March 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why was this upvoted? I think this is a legitimate question asking to write code. You are providing an algorithm for a specific case, not implementing a class.

- anon July 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Employee
{
public: 
	Employee(unsigned id, string fName, string lName, Employee* manager = nullptr);
	void showSubOrdinates() const;
	void addSubordinate(Employee* mySubordinate);
private:
	unsigned id;
	string firstName;
	string lastName;
	Employee * myManager;
	std::vector<Employee*> mySubordinates;
	void showMyInfo() const;
};

Employee::Employee(unsigned id, string fName, string lName, Employee* manager)
	:id(id), firstName(fName), lastName(lName), myManager(manager)
{
	if (myManager != nullptr)
	{
		myManager->addSubordinate(this);
	}
}

void Employee::addSubordinate(Employee* mySubordinate)
{
	mySubordinates.push_back(mySubordinate);
}

void Employee::showMyInfo() const
{
	std::cout << firstName << " " << lastName << endl;
}

void Employee::showSubOrdinates() const 
{
	for (vector<Employee*>::const_iterator it = mySubordinates.begin(); it != mySubordinates.end(); ++it)
	{
		(*it)->showMyInfo();
	}
}

int main()
{
	unsigned id = 0;
	Employee philip(id++, "Philip", "Smith");
	Employee joe(id++, "Joseph", "Davis", &philip);
	Employee rebecca(id++, "Rebecca", "Hall");

	joe.addSubordinate(&rebecca);

	philip.showSubOrdinates();
	joe.showSubOrdinates();

}

- charlie July 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
#include <string>
using namespace std;

class employee
{
int ID;
string LName;
string FName;
employee* M;
employee* Sub;

public:
employee():ID(-1),LName(NULL),FName(NULL),M(NULL),Sub(NULL)
{
;
}
employee(int n,string fn,string ln,employee* manager=NULL,employee* subor=NULL)
{
ID = n;
LName = ln;
FName = fn;
M = manager;
Sub = subor;
}
void set_sub(employee * s)
{
this->Sub = s;
}
void Print_Infor()
{
printf("\n%d\n",this->ID);
}
employee * get_sub()
{
return this->Sub;
}
void get_subor()
{
this->Print_Infor();
employee* p;
for(p=this;p->get_sub()!=NULL;)
{
p=this->get_sub();
p->Print_Infor();
}
}
};

int main()
{
employee b(1,"hua","jun");
employee VP(2,"He","pin",&b);
b.set_sub(&VP);
b.get_subor();
getchar();
}

- Jun March 03, 2013 | 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