Amazon Interview Question for Software Engineer / Developers






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

this only works when N is odd...and i

N(N^2-1) == N(N+1)(N-1)

we need to show that there are atleast three 2's and and one 3 in this product so that it can be divisible by 24

if N is odd.. N+1 and N-1 are even...and even numbers are divisible by 2...so we have two 2's here...another 2 comes from the fact that two consecutive even numbers always have an extra 2 in their product...so this makes it three 2's

and any three consecutive numbers will be divisible by 3...

- vi December 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

N(N^2-1)=(N-1)N(N+1)
means it must be divisible by 2 and 3(Why?)

since 24=2X2X2X3
so N(N^2-1) is divisible by 24.

- Anonymous December 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It simply means that it's divisible by 6 not by 24.

- Anonymous December 10, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

for odd Ns,
(N-1) - is even, so div by 2 (smallest is 2)
N is odd
(N+1) - is even, next num div by 2 (smallest is 4=2x2)

N(N+1) is div by 3
So, 2x 2x2 x3 = 24 is a factor

- Anonymous December 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

is it guaranteed that if n is odd then n(n+1) is divisible by 3 ?
wat abt n=7
(7-1) x 7 x (7+1) = 6 x 7 x 8
here, 7x8 = 56 % 3 = 2.. so ur assumption is not true

- Rj December 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

its ok..
(n-1)n(n+1) is divisible by 3 for any no.
as these are consecutive

6,7,8

- PKT September 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Let p = n*(n^2-1) = (n-1) n (n+1). Being product of 3 consecutive numbers, p is divisible by 3.
Also as n is odd, let n = 2k+1; then p = (2k) (2k + 1)( 2k + 2) = 4k(k+1)(2k+1). As k and k+ 1 are two consecutive numbers so it is divisible by 2 and hence p is divisible by 8.
As 3 and 8 are co-prime, p is divisible by 3*8 = 24.

- Kailash Gupta August 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what do u mean: n*(n^2 - 1) is div by always?
if so, n = 4 and result = 60.

correct the question

- Anonymous December 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

pardon for the error in Q,here n is odd and >=3

- googler December 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Above statement true only if "N" is odd . Plz be carefull while posting such questions.

- Ajay December 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

easy to work out using induction
1.let n=3,3*8=24
2.assume n=k k*(k^2-1) is div by 24
3.let n=k+2
(k+2)*((k+2)^2-1)=k*(k^2-1)+6(k+1)^2

the right side of the above equation are div by 24
Done

- Derek December 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n(n^2-1) = n(n-1)(n+1)
24 = 1*2*2*2*3

Out n, n-1, n+1 two are definitely even. They are divided out by two 2's in 24s.
Remaining is 6.

Out of n, n-1, n+1, one is definitely divisible by 3. That number is divided by the 3 in 24.

Now out of the two even numbers in n, n-1, n+1 one is double of one odd number, and one is definitely double of one even number.

So that number is divided out by the remaining 2. Rest remaining is 1. Thus dividable

- Funky Phoenix December 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n(n^2-1) -> (n-1)n(n+1)----eq.1

24 = 2*3*4---eq.2

suppose we assume that eq.1 is divisible by 24, now next odd n would be n+2 representing eq.1 as

(n+1)(n+2)(n+3)

suppose we add the same factor to eq.2 then it becomes 4*5*6->120 which is also divisble by 24 and represents 5 in equation 1

i am not sure if it the correct proof

- ketz January 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n(n^2-1) can be written as (n-1)*n*(n+1)
1) that means it will always be divisible by 3 (because one of the three contiguous number must be multiple of 3)
2) n is odd and >=3 that means it can be 2*3*4, 4*5*6, 6*7*8 .....
So it can be clearly seen that one of the (n-1) and (n+1) will be divisible by 2 and other by 4 for sure.{n-1 & n+1 are two continuous even numbers}

By 1) and 2) we can clearly say that (n-1)*n*(n+1) will always be divisible by 24 (3*2*4).

- Pgrox January 12, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n*(n-1)*(n+1)
is div by 3 ---true

and is n>3 and odd true is always divisible by 8.because any odd no. contains n-1
and n+1 and multiple of both is div by 8.


eg. n=7 7*8*6 %24=0

n=9 9*8*10%24=0
hence 2*2*2*3 =24

- bhavesh.mnnit January 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

n*(n-1)*(n+1)
is div by 3 ---true

and is n>3 and odd true is always divisible by 8.because any odd no. contains n-1
and n+1 and multiple of both is div by 8.


eg. n=7 7*8*6 %24=0

n=9 9*8*10%24=0
hence 2*2*2*3 =24

- bhavesh.mnnit January 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

P = n*(n^2-1) = (n-1)*n*(n+1)
let, n = 2m+1 (n being odd)
We have, P = (2m)*(2m+1)*(2m+2) = 4*m*(m+1)*(2m+1)
Now, the formula for sum of squares of integers as:
S = 1^2 + 2^2 + ... + m^2 = [m*(m+1)*(2m+1)]/6
Therefore, m*(m+1)*(2m+1) = 6S
Hence we have, P = 4*6S = 24S

- Anil January 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Great!

- Anonymous January 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can use the math reduction too.
4m(m+1)(2m+1) = 24k
when m = 1, that is right
assume m is right, we need to prove m+1 is right too. it is easy to prove it.

- yuweihui2 January 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Man, do Amazon ask so simple questions in round 3????
There could be many methods, as explained in previous post.....
n*(n^2-1) = n(n+1)(n-1)
(1) when n is 'odd'; (n+1) and (n-1) are even. We get 2*2*2 from this, since n>3
(2) n, n-1, n+1 are consecutive, so one has to be multiple of 3.
From 1 and 2, we get 2*2*2*3=24

- shekhar2010us February 10, 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