Amazon Interview Question


Country: United States




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

Is it the right way?? please suggest. :)
=====================================

package com.amazon.universe.main;

import java.io.File;
import java.util.LinkedList;
import java.util.Queue;

public class FindFileswithGivenExtension {

	public static void main(String[] args) {

		/*define the appropriate file path here*/
		File file = new File("D:\\G_Mlab\\neural_network"), temp;
		Queue<File> allFiles = new LinkedList<File>();
		allFiles.add(file);
		File[] files = null;
		while (!allFiles.isEmpty()) {
			temp = allFiles.poll();
			files = temp.listFiles();
			for (File innerFile : files) {
				if (innerFile.isDirectory())
					allFiles.add(innerFile);
				else if (innerFile.isFile()
						&& innerFile.getName().endsWith(".pdf")) {
					System.out.println(innerFile.getAbsolutePath());
				}
			}
		}
		System.out.println(files.length);
	}

}

- Gautam Tyagi July 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Is it the correct way as expected.

package com.amazon.universe.main;

import java.io.File;
import java.util.LinkedList;
import java.util.Queue;

public class FindFileswithGivenExtension {

	public static void main(String[] args) {
		/* define the appropriate file path here*/
		File file = new File("D:\\G_Mlab\\neural_network"), temp;
		Queue<File> allFiles = new LinkedList<File>();
		allFiles.add(file);
		File[] files = null;
		while (!allFiles.isEmpty()) {
			temp = allFiles.poll();
			files = temp.listFiles();
			for (File innerFile : files) {
				if (innerFile.isDirectory())
					allFiles.add(innerFile);
				else if (innerFile.isFile()
						&& innerFile.getName().endsWith(".pdf")) {
					System.out.println(innerFile.getAbsolutePath());
				}
			}
		}
		System.out.println(files.length);
	}

}

- gautam Tyagi July 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The interviewer is probably interested if you can use bash instead of coding something already implemented very well If this is the case than I would reply something like:

find temp/reg -name '*.c'

- autoboli July 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Or it might just be the opposite. He may be interested in testing if you know syscalls and how find works under the hood.

- 010010.bin July 17, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sure, it could be anything. I have experienced a question of type 'how would you collect phone numbers from ~10M if=ox XML files'. The good answer was grep or sed, the red flag was to implement your own code.

- autoboli July 17, 2015 | Flag


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