Amazon Interview Question for Software Engineer / Developers






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

Make depth-first search using stack for example.

- m@}{ April 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It can be solved very easily using unix shell scripting

- Anonymous April 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you plz elaborate thru some example script.

- Ratnesh April 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

grep -l keyword *
OR
ls * | grep -l keyword

I don't have unix prompt but one of those should word, * will search recursively on sub directories

- Mat April 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

grep command works

- guest April 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think if you need to search recursively, you need -R option.

- AW April 20, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In *nix:

#find . -name <filename>

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

sorry mis-read the question please disregard my comment.

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

grep -e '\b[0-9]\{10\}\b' *

this will find matching files from entire directory

- ash.388235 April 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we dont have the filename.. we have to search recursively thru the folders until we end up near a file.

- shady April 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class fileOperation {

public static void main(String[] args) throws IOException {
String loc = "temp";

File dir = new File(loc);

listRecursive(dir);
}

private static void listRecursive(File dir) throws IOException {

File[] listFiles = dir.listFiles();

if(listFiles != null){
for(int i=0;i<listFiles.length;i++){
if(listFiles[i].isDirectory()){
listRecursive(listFiles[i]);
}else{
//System.out.println(listFiles[i]);
checkPhoneNumber(listFiles[i]);
}
}
}
}

private static void checkPhoneNumber(File file) throws IOException{
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ( (line = br.readLine()) != null)
{
// Print phone number to screen
try{
long num = Long.parseLong(line);
System.out.println(file.getAbsolutePath());
System.out.println(num);
}catch (NumberFormatException ne){
//System.out.println("NE");
}

//System.out.println (line);
}

br.close();

}
}

- Manoj Kumar April 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey71065" class="run-this">/* The class name doesn't have to be Main, as long as the class is not public. */
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
java.io.BufferedReader r = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
String s;
while (!(s=r.readLine()).startsWith("42")) System.out.println(s);
}
}

</pre><pre title="CodeMonkey71065" input="yes">
23</pre>

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

egrep -r [0-9]\{10,\} *

- tux June 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the above code can find a text file which contains a phone number...this can go recursively..
this will only search for 10 or more digit phone numbers...(10,15 will search 10 to 15 digit phone numbers... )

- tux June 13, 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