Amazon Interview Question for Software Engineer in Tests


Country: United States




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

ls |grep "[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}"

- rtpdinesh March 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi Dinesh,
Good one.
But just a correction or two:
1) '.' matches any single character except end-of-line. So, it has to be escaped when we want to match '.'
2) the strings such as 1234.123.341.243 which has more than 3 digits (1234) should not be included.
so, the final command might look like:

ls -R| grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | grep -v '[0-9]\{4,\}'

-v switch: exclude those that match the pattern ( here 4 or more occurrences of digits)

- viv March 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

egrep '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}' filename

- Dev March 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use the above command with find command:

find /repository -iname '*.*' | xargs egrep -i '[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}'

Find searches (case insensitive) over all the files in /repository, and for each file, performs an egrep.

- Learner March 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Glad to see this answer.


What this question is really testing, from the interviewer's perspective, is whether you're good at solving problems in the easiest way possible. Some people will go on to write 200 lines of ad-hoc Java code to parse for the string.

- eugene.yarovoi March 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cool answer.

- flyinocean.mitbbs March 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if a file has 192.168.256.256 this is not an ip address
And what about ipv6 addresses?

- Andy May 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

grep -l <pattern> *
duh ...

- Anonymous March 26, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What if a file has 192.168.256.256 this is not an ip address
And what about ipv6 addresses?

- Andy May 31, 2012 | 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