Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

A basic file system can be shown as managmenet of data in Files & Folders. It should also manage the space available.

FIles and folder structure can be representd using Composite pattern as below:

class FileEntity
{
  // members common to File & Folder
  // create, copy, delete, move, getInfo, open, etc
};

class Folder : public FileEntity
{
  // a folder can have multiple FileEntity (folders or files)
  vector<FileEntity> m_VecFileEntity;
  // members of Folder
};

class File : public FileEntity
{
  // members of File
};

class Drive
{
  // members of Drive
  // getFreeSpace, getTotalSpace, createPartition, etc
};

class FileSystem
{
  vector<FileEntity> m_VecFileEntity;
  vector<Drive> m_vecDrives;
};

- sand February 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Shouldnt the drive class have a vector of folders as its member? If not, could you please explain why not?

- bdeesh February 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Agreed. There has to be closer relationship between Drive & FileEntity.

- sand February 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The two classes are
1. Folder
2. File

Now folder can have sub folders and files.

class Folder
{
ArrayList<Folder> subFolderList;
ArrayList<File> fileList;


Folder(File file)
{
fileList.add(file);
}
Folder(Folder folder)
{
subFolderList.add(folder);
}
Folder(Folder folder, File file)
{
folder.addFile(file);
subFolderList.addFolder(folder);
}

}

class File
{
String fileName;
MetaData metadata;

File(String fileName, MetaData metadata)
{
this.fileName = fileName;
this.metadata = metadata;
}


}

- Sim February 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Composite pattern should be used here... Directory has files and 0 to many Directories in it again.
Directory and File can be identified by their properties.

- hello world February 07, 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