Amazon Interview Question for SDE1s


Country: India
Interview Type: In-Person




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

Initially choose some number k of the form 7x10^x for some x, where k > the given number N.

Suppose k = 7000,
1. Place a 7 one position at a time and see if N divides k. For ex: 7007, 7070,7700.
2. Then place 2 7's at positions and see like in 7077, 7707, 7770 etc. and test if N divides k.

In essence, the problem is asking to generate the possible combinations of 7's and 0's and then check for divisibility. The problem is combinatorial in nature and my solution has exponential time complexity in the number of digits of N.

- Murali Mohan February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

print 0

- 123 February 10, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

very good answer for a confused question

- aka February 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question is kind of vague. Could you clarify? The smallest number in what?

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

Suppose n has m digits. We will generate all m, m+1,m+2 ,m+3.. digit numbers comprising of digits 0 and 7 in the increasing order and then check for each generated number if it is divisible by n.

Suppose n is 3812. In this case we will generate all the 4,5,6.. digit numbers consisting of 0 and 7 through combination, for ex the first one will be 7000, 2nd 7007, 3rd 7070, 4th 7077, 5th 7700, likewise and check for each generated number if it is divisible by n. We will keep on generating the numbers until and unless we find one which is divisible by n.

In other case, suppose n is 8812. In this case we will start from generating 5 digit numbers consisting of 0 and 7 as the maximum 4 digit number 7777 is smaller than the n itself.

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

Use 2 queues:
queue1: for numbers with 0 at unit place
queue2: for numbers with 7 at unit place
get minimum of these two queues.Check if it is divisible by n. if yes return it else insert in queues as per the critetia.

- Nitin February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Nitin : can you please provide algo for the same.

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

unless i'm missing something very obvious, wouldn't any combination of 0 *and* 7 will be divisible by 7 ?
so if an integer N is divisible by any combination of 0 and 7 - it is divisible by 07 - which is obviously be smallest of any such combination.
This is because

(07)+ is divisible by 7
(70)+ is divisible by 7

Of course i'm assuming that the question implies that we must use both 0 and 7.

That said, the question is a bit vague and certainly needs more clarification.

- kk February 14, 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