Amazon Interview Question for Quality Assurance Engineers


Country: India
Interview Type: In-Person




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

public int countTrailingZerosOfFactorial(int n) {
    int count = 0;
    for (int powerOfFive = 5; n / powerOfFive > 0; powerOfFive *= 5) {
        count += n / powerOfFive;
    }
    return count;
}

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

Good Solution

- Vishal S Kumar January 23, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

24. Factorize multiples of 5
5 = 5x1
10 = 5x2
15 = 5x3
20 = 5x2x2
...
25 = 5x5 (one extra 5)
..
50 = 5x5x2 (one extra 5)
...
75 = 5x5x3 (one extra 5)
..
100 = 5x5x4 (one extra 5)

All of the 20 multiples of 5 up to 100 have one 5 each. The multiples 25,50,75 & 100 have one extra 5 each. Hence the total number of 5s = 24. Each of these twenty four 5s when multiplied by 2(which are at least 50 in number) yields a zero and hence the total number of 0s = 24.

- Murali Mohan January 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But how would you write code?

- Banti September 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The easiest way is to check the maximum power of 5 which can be there in factorial.

10=5x2
If we are calculating the factorial then n!=n x n-1 .... 1= A x 5^p x 2^q, hence it will depend on the value of p which will define the number of zeros.

Steps to find the max number of 5 is
If the number is say Z then max power of 5
p= z/(5) +z/(25) + z/(125)...z/(5^n) till z/(5^n) results a integer number.

- satyajeettripathy January 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int Zeros(int n)
{
int k=0,nb=0;
while(pow(5,k+1)<=n)
{
k=k+1;
nb=nb+n/pow(5,k);
}
return nb;
}

- TUNISIA January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 votes

بسم الله الرحمــــــــان الرحيـــــــــــــــــــــــم

انه الحل للمسألة الاعلامية
مع الشكر

- TUNISIA January 26, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@TUNISIA

ye kya chutiyaapa hai ??

- Anonymous October 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

f(n) = n/5 + f(n/5);
base case: f(n)=0 iff n<5

- llq February 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CalculateNumberOfZeros {

	public static void main(String[] args) {
		
		findMaxPowerof5(100);
	}

	public static void findMaxPowerof5(int num) {
		LinkedList<Integer> link = new LinkedList<Integer>();
		int totPower = 0;
		for (int i = 1; i <= num; i++) {
			if (Math.pow(5, i) <= num) {
				totPower += num / Math.pow(5, i);
			}
		}

		System.out.println("Number of zero=" + totPower);

	}
}

- Ravi Kumar February 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

output-
Number of zero=24

- Ravi Kumar February 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In Excel, cell A1: =FACT(100) Result is 93326215443944200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

In cell B1: =LEN(A1)
Copy the significant digits out of A1 (933262154439442)
In cell A2: =A1/933262154439442
In cell B2: =LEN(A2)
Number of zeros = B1-B2=14

- Marianne April 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This question is worded incorrectly, there are 30 zeros contained in 100!

100! = 
9332621544394415268169923885626670049071596826438162146859 29638952175999932299156089414639761565182862536979208272237582511852109168 64000000000000000000000000

The question should be "How many consecutive zeros are there at the end of 100! (100 factorial)."

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

ok , then what is the program to get 30 as the answer?

- Anonymous November 22, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class FactMag
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double no=0,fact=1;
System.out.println("enter a number");
no=sc.nextDouble();
double r=0,c=0;
for(double i=1;i<=no;i++)
{
fact=fact*i;
}
System.out.println(fact+" ");
while(fact>0)
{
r=fact%10;
if(r==0)
c++;
fact=fact/10;
}
System.out.println("no of zeros are "+c);
}
}

- naveen kothiyal October 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class FactMag
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
double no=0,fact=1;
System.out.println("enter a number");
no=sc.nextDouble();
double r=0,c=0;
for(double i=1;i<=no;i++)
{
fact=fact*i;
}
System.out.println(fact+" ");
while(fact>0)
{
r=fact%10;
if(r==0)
c++;
fact=fact/10;
}
System.out.println("no of zeros are "+c);
}
}

- naveen kothiyal October 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

each divisible by 5 and divisible by 10 are 0 contributors. but 25,50 ,75, 100 are two zeros contributors there are 8 5s and 8 10s making it 16 + (4*2) so totally 24 zeroes

- Joshua Kumar January 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

143

- Akil February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think problem is about zeros contained in the 10 Factorial not just trailing 0's

x = 1
for i in range(1,101):
    x*=i
cnt = 0
for val in str(x):
    if int(val) == 0:
        cnt += 1
print cnt

- Anonymous January 14, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

def f(n):
	if n==1:
		return 0
	if n%10==0:
		c=0
		a=n
		while a%10==0:
			a=a/10
			c=c+1
		return c+f(n-1)
	if n%5==0:
		c=0
		a=n
		while a%5==0:
			a=a/5
			c=c+1
		return c+f(n-1)
	return f(n-1)

100! will have 23 zeroes

- anon123 January 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I'm really sorry but the correct answer is 24 - that's why you've got -2 vote -

- TUNISIA January 26, 2014 | 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