Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

The actual code for this seems beyond the scope of an interview but the solution I've sketched out is:
1. Parse the input string into a tree structure with = at the root and each node either an operator (+-/*) or a value. The tree is structured with lower order operators higher in the tree. Take care to respect brackets when creating the tree.
2. Evaluate each side of the tree root. Each node evaluates to a composite value of x^2's, x's and a constant. Take care when multiplying two sub-nodes that have x^2 and x values. If you ever hit an x^3 value or higher order x, throw exception.
3. Subtract the right hand side values from the left hand side values to get something in the form ax^2 + bx + c = 0. Use the quadratic formulae to solve it.

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

Although your solution is perfectly fine and can be used to solve more generalized equations but we can take advantage of the special assumptions given for the input. Thus we can avoid constructing a parse tree.

We scan the input and process LHS and RHS of the equation and identify tokens and processing them according to the operators encountered. After this the solution is trivial.

- EOF November 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I know I didn't realise use the domain restrictions to simplify the solution, but I can't really see how since there is no restriction on brackets (right?) for instance how can you parse some crazy complex brackets as tokens? Something like:
((4*(5-X+X*(4/5))+1)*6)*(7*(X/(6+1)))+5X=0

- shinsetsu November 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

these folks were talking on chat and it boiled down to heavy restrictions

well it boiled down to "don't waste ur time on them because they are too dumb to even state the problem clearly enough to help them"

- S O U N D W A V E November 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

some absolute idiot, not saying it is you, kept begging people to help him to code this from around a week ago (on chat)

expand both sides out, collect like terms (3 counters a2++, a1++, a0++ on left side, and -- when seen on right side... for coefficients of a2*x^2 + a1*x + a0).

After all that is said and done, check if a2 is 0, if so easy...

If a2 is not zero, check discriminant and build 3 cases on that

- S O U N D W A V E November 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 votes

should be a2+=(number in front of x^2), a1 += ( in front of x)

and -= on right side

- S O U N D W A V E November 01, 2013 | 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