Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

If it should be binary tree, I believe it`s fine. You can decide that node to the left is a file/folder inside the same folder as this one (it`ll be null for /). And right is a link to first file/folder inside this one.
So actually you`ll have linked list for file inside this foder (if nothing inside it or not a folder then null) and pointer to the next file/folder for parent folder (if last file/folder inside parent folder, then null)
Let`s try with pseudographics

"/"
     \
    "/etc"
    /     \
  "/usr"   "/etc/X11"
  /        /          \
"/boot"  "/etc/fstab"  "/etc/X11/xorg.conf"

- Anton January 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you`d like to have links in your filesystem (and you probably would) such as "/etc/.." -> "/".
My solution is that you need to add new type of file, where right edge is leading to linked file/folder.

- Anton January 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't quite get it. So the left subtree contains all the directories within the current directory, and the right subtree is the first file within the current directory?Could you please draw out the binary tree with example?

- Kelvin January 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I`m not sure how actually I can draw it any other way.
I can only convert it to windows filesystem (and change formatting slightly for convenience
(some left & right links skipped of course, left subtree starts under '/' and right under '\' )

"C:\"
     /      \
   null    "C:\WINDOWS"
           /             \
     "C:\temp"         "C:\WINDOWS\System32"
         /              /                 \
"C:\boot.ini"   "C:\WINDOWS\System"    "C:\WINDOWS\System32\notepad.exe"

Does it make more sense?

- Anton January 21, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Try to perform list files (LS -l in linux ) and do BFS for the list of files

- RASHMI BS January 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think, File system can be implemented using binary trees (or btrees etc). For example, in linux root directory can take the place of a root of the tree, with other files and directories underneath it.

eg: /
bin... etc ....

For adding a new directory we need to identify its parent directory in the tree and insert into it.

- SS January 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

but doesn't binary tree only have two children per node, whereas each directory in file system has multiple subdirectories and files

- Guy January 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

huge what?

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

Cant this be done using N-ary trees with first child and next sibling pointers?

- Another guy May 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Cant this be done using N-ary trees with first child and next sibling pointers?

- Another guy May 30, 2014 | 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