Amazon Interview Question for Software Engineer / Developers






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

I am not expert but here is my solution.
1. delete all spaces before and after (
%s/ (/(/g
%s/( /(/g
and then add one space before and after bracket
%s/(/ ( /g

do same for ) bracket.

let me know if there is some optimal solution.

- sonu March 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not expert but here is my solution.
1. delete all spaces before and after (
%s/ (/(/g
%s/( /(/g
and then add one space before and after bracket
%s/(/ ( /g

do same for ) bracket.

let me know if there is some optimal solution.

- sonu March 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

$str="foo (bar (new Point(x,graph.getY()) ));";
$str =~ s/(\s*)([\(\)])(\s*)/ \2 /g;

- Anonymous March 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{$str =~ s/([\(|\)])/\s$1/g}
Replace if either of ( or ) is found and replace it with a space '\s' followed by $1 is either ( or ) and do this globally

- Anon March 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

do u think ur command will keep only once space before and after bracket. what if bracket already have space

- sonu March 02, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

echo "foo (bar ( new Point (x, graph.getY()) ))}" | sed 's/[ ?]//g'|sed 's/(/ ( /g;s/)/ ) /g'

- Psh April 13, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is wrong because you eliminate the space between new and Point as well.

- Anonymous July 27, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

echo "foo (bar ( new Point(x, graph.getY()) ));" | sed 's/(/ ( /g'|sed 's/)/ ) /g'|tr -s " "

replace ( with " ( " and ) with " ) " and then compress all the spaces using tr to one space.

- Sumansmita Sahoo June 20, 2009 | 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