Amazon Interview Question for Software Engineer / Developers






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

Your answer seems incorrect, it checks for only 1 digit from 0-9 range. Instead it should be some thing like [1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]. Can suggest a better way to write this expression in perl?

- Killer Drama September 10, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi Killer. You were right. Here is my example and output

#! /usr/bin/perl

print "Enter a 9 digit number: ";
$number = <>;
chomp $number;

if ($number =~ /\d{9}/) {
print "$number is a 9 digit number\n";
}
else {
print "$number is not a 9 digit number\n";
}


Output & Test Case
-------------------

bash-2.05$ perl match.pl
Enter a 9 digit number: 234567890
234567890 is a 9 digit number

bash-2.05$ perl match.pl
Enter a 9 digit number: 12345
12345 is not a 9 digit number

bash-2.05$ perl match.pl
Enter a 9 digit number: a1234
a1234 is not a 9 digit number

bash-2.05$ perl match.pl
Enter a 9 digit number: a12345678
a12345678 is not a 9 digit number

- Metallicatony September 11, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Metallicatony

So did you give a wrong answer in the interview? And did you make it to the next round? I am worried because I did something similar and I am waiting for their call.

- perllove September 12, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The answer would be [0-9]{9}. This looks for a number having exactly nine repetitions.

- Anonymous September 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

But this wouldn't give numbers having exactly 9 digits i guess? it would give numbers/strings having 9digits or more.
For e.g 989842342342342897 would also be eligible, and it's not a 9 digit nubmer.
The correct code would be i guess, [^0-9][0-9]\{9\}[^0-9] if you were looking for exactly some nine digit number.

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

$number=~ /[0-9]{9}/

- Smita August 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

All the above solutions wont give exactly 9 digits. Try this. /^\d{9}$/

Complete Code:

#! /usr/bin/perl

print "Enter a 9 digit number: ";
$number = <>;
chomp $number;

if ($number=~ /^\d{9}$/) {
print "$number is a 9 digit number\n";
}
else {
print "$number is not a 9 digit number\n";
}

- Ram November 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We have limited with ^ and $ to exactly 9 digits. Hope I have clarified.

- Ram November 02, 2011 | 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