Interview Question






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

suppose we want to calculate x^n then
1.Check both values are inputted correctly or not.

2.Check for trivial case when x=0 then for any value of n it should return 0.

3.when n=0 it should always return 1 whatever x be.

4.check for negative values of x and n.
i)If n is negative then result should be always less than or equal to x.

5.Check first for smaller values of x and n i.e for 2,2 3,4 etc.

6.Now check for larger values of n and x and see the results.

- ALGORITHMIST February 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x +ve, 0,-ve
n +ve, o,-ve

check when n=0, irrespective of x, the return value==1.
check for n=1, then x should be returned.
n=2 -> x*x is your expected output irrespective of sign of x,
n=3, x=-v3, then x cube with a -ve sign should be returned..

** when n becomes negative, if x is zero, its a divide by zero exception
n is -ve, and x is +ve or -ve, the result is always <1, so if the return value is an int,its going to be rounded to a 0 or 1..

** a test case for the overflow.. if x and n are large enough intgers, the overflow will cause the sign bit to on.

- nk August 12, 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