Amazon Interview Question for Quality Assurance Engineers


Team: Kindle
Country: India
Interview Type: Written Test




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

I think we need to write the test data, not a code.
It should be something like that:
int (2, 2)
number of digits after the coma > precision (2.23434, 1)
number of digits after the coma = precision (3.23, 2)
number of digits after the coma < precision (4.23, 5)
zero (0, 0)
precision zero (3.45, 0)
negative (-1.2334, 3)
negative precision (3.34, -5)
empty ( ,3)
empty precision (3.245, )
etc.

- F August 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Exactly! the question is all about test data generation and not the prog

- Anonymous August 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

for the example given, when rounding off to two digits the output should be 3.46, shouldn't it?? or did i miss something?

- phantom93 July 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes u are right thats a small mistake from my side.....it should round off to 3.46....(i.e to the 2nd decimal place)

- Surekhag28 July 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Yo can see code + Test cases here www "dot" gohired "dot" in/2014/07/test-cases-for-round-function "dot" html

- Devil July 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I can confirm that the implementation given at the url is WRONG.

- Teh Kok How September 04, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

float round(float num, int pre)

int mul = pow(10, pre+1);
  num = (int)((num * mul + 5)/10);
  num /= mul*10;
  return num;

- jerome.moon August 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

firstly v can get 3.4567 as .4567 by subtracting the integer part from the no.. then we can multiply by 1000 and then take %10 and then check that number if it is greater than or equal to 5 then v can round off to next digit otherwise keep it as it is

- anonymous July 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there is no point in subtracting to get fractional part you can just ignore the subtraction and continue with the next part

- phantom93 July 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float fl,j;
int n,k,i;
clrscr();
printf("enter float value: ");
scanf("%f",&fl);
printf("enter precision: ");
scanf("%d",&n);
fl=(float)fl*pow(10,n);
printf("%f ",fl);
if((int)(fl*10)%10>=5)
fl=(int)fl+1;
else
fl=(int)fl;
fl=(float)fl/pow(10,n);
printf("%f",fl);
}

- Anonymous July 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You Solution seems to be correct.

- ravio July 29, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

assert(round(1234.5678, 1) == 1234.6);
assert(round(1234.5678, 2) == 1234.57);
assert(round(1234.5678, 3) == 1234.568);
assert(round(1234.5678, 4) == 1234.5678);
assert(round(0.1234, 1) == 0.1);
assert(round(0.1234, 2) == 0.12);
assert(round(0.1234, 3) == 0.123);
assert(round(0.1234, 4) == 0.1234);

double round(double num , int n)
{
	unsigned long long tmp, tmp1;
	tmp = num * pow(10, n+1);
	tmp1 = num * pow(10, n);
	if (tmp%10 >= 5)
		tmp1++;
	return tmp1 / pow(10, n);
}

- Teh Kok How September 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#python 3.3.2
import random
def generate_ran_nums():
	# 
	# Generated random data in the format (float(rounded to 4 decimals), randint)
	#
	num = round(random.uniform(0,9),4)
	ran = random.randint(0,9)
	return num, ran

- Python September 08, 2014 | 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