Intel Interview Question for Software Engineer / Developers






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

This problem can be easily solved by defining a Graph dependency and testing for a circular path as explained below:

For a given set of files you can create a Graph consisting of two nodes and an edge between them if the file "B" is included in the file "A" as

A -> B

As you scan the file, collect all such pairs for a given set of files recursively and construct the graph incrementally for each such pair and thus we can easily use the graph traversal algorithms to find and detect any circular paths that may exists from a given node "X" by employing either the DFS (depth first search) or BFS (breadth first search) algorithms.

Every time a new file need to be included check for any such possible cicurlar paths and if you detect one then do not include the file otherwise continue recuversively until there is no circular path exists.

- Jagga Muddasani May 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I hope it does not go for recursion as every header #ifndef and #defines to avoid mutiple inclusions. Here the problem generally comes with declarations : one type declaration includes other which uses the first one inside.
Eg:
// In A.h
Class A{
.....
public:
B* b;
....
};

// In B.h
Class B
{
.....
public:
A* a;
....
}

In this situation each class declaration is not complete as the other is not complete.
These kind of problems can be avoid by just declaring other type in each header.
// A.h
class B;
class A{
.....
B* b;
....};

//B.h
class A;
class B{
....
A* a;
.....
};

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

int f(char* fileName, size_t n)
create Stack [allFiles] out of all the include# in fileName
Have a hashtable where key is the absolute header file name.
while(!allFiles.empty())
{
File f = allFiles.pop();
if(!hashtable.key(f.full_path()))
{
hashtable.put(f.full_path(), f);
}
Add all the include# from file f if it's not in allFiles Stack

}

- Mat May 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This code can be solved by using back tracking and we need 2 hashmaps to solve. 1 hash is for total number of #includes which can be less than equal to the number of files we have in the set and the 2nd hash map is for the file number typically from 1 to n.

Enjoy !!

- Rasmus May 26, 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