Amazon Interview Question for Software Engineer in Tests


Country: India
Interview Type: Phone Interview




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

Stack is the right data structure for this.

- Victor July 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Consider a tree structure for the directory.

Read the input and while input string is not over do following for
each element after 'cd '


switch(ch)
current directory will be root.
when command is
case 1. cd a

two possibilities
a) There is a child directory a, you need to go to this node
b) No child directory called a stop and print error

case 2 cd .

Do nothing. '.' means current directory

case 3 cd ..

Go to parent

- words&lyrics July 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Going to parent will be expensive(Unless yiou modify a Tree to have parent pointer)..... We Should to use stack to first find out the path (i.e. without "." and "..") once we have the path we can follow Tree to go to the correct directory

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

+1 manan. I guess question is asking you to write program to covert such a path into an absolute path. (which will be passed to file system).

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

Stack is good - but... you cannot validate the path, unix will not let you to do
cd /blabla/../tmp

- Gadolin July 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think you can make use of a doubly linked list while storing the ptr to the last element...
split the string based on '\'. When you find a char insert it at the end of the DLL if it's a valid path. When you encounter a '.' do nothing. When you encounter a ".." delete the last element in the DLL.

Does that make sense ?

- G July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

answer is : b

algorithm : use stack adt to store the input . pop whenever .. comes

- chacha_choudhary July 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ans is 'a'

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

ans is a

- charan June 19, 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