Amazon Interview Question for Software Engineer / Developers






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

// Define a structure for graph node
struct Node
{
struct arch *first;
int info;
struct Node *next;
};

// Define a structure for graph edge
struct arch
{
struct Node *second;
struct arch *next; // next arch for the same node
};

class Graph
{
private:
struct Node *startNode;
public:
Graph():startNode(NULL){ }
struct Node *getNode();
struct arc *getArc();
void populateNode(struct Node *); // link node with the archs it is pointing too.
};

- vipin December 18, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please advise if this is correct.

struct GraphNode
{
void *data;
struct GraphNode* children;
}gNode;

class Graph
{
public:
Graph(gNode node):root(node){};
~Graph();
void insert(gNode node);
void delete(gNode node);
int totalNodes();
private:
gNode* root;
};

- tt September 08, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

afsd ydyydus[/'aozjg fd[
'#;p[;#/.///.m,
,/';l'p[;/'
/';.';';

- ally July 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

so what i am a popstart who cares

- ally34455 July 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Node and arc are same as in vipin's solution
But I would define Graph differently

class Graph
{
private:
struct Node *startNode;
public:
Graph():startNode(NULL){ }
struct Node *addNode();
struct arc *addArc();
void traverseGraph();
void deleteNode();
void deleteArc();
void populateNode(struct Node *); // link node with the archs it is pointing too.
};

- mp March 07, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// custom data here....
struct node
{
int foo;
int bar;
// user friendly way to recognize a node
string nodeId;
}
class Graph
{
// create a preset graph
Graph(vector<node*> data, int[][] relationMatrix);
// create empty graph with no nodes....
Graph();
addNode(node* toAdd, vector<string> neighBours);
deleteNode(string id);
node* getNode(string id);
vectot<node*> getNeighBours();

int getNodeCount();
traverse(node* startNode);
// will start from first node added
traverse();
}

- KAK May 24, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

crap

- tt July 06, 2012 | 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