## Amazon Interview Question for Financial Software Developers

Country: United States

Comment hidden because of low score. Click to expand.
39
of 41 vote

Ask the class to stand up and make pairs, if one student is left out write '1' else write 0. tell the left out student to sit down and ask one person in each group to sit down. Repeat the process and append '1' or '0' to your number, until no student is left standing. You will get the binary representation of the number of students in reverse order.
Eg: lets say there are 23 students in the class
Students standing 23 11 5 2 1 0
Solution 1 1 1 0 1 0

we have a string 111010, and the binary representation of 23 is 010111.
This is just using divide and conquer O(lg n)

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

Good one...!!

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

solution is so nice

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

solution is so nice

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

Excellent Thinking Great job man

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

its nice

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

excillent too good

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

Hello Mrs Dear eshank.rastogi ,
Hope you are satisifed now.

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

no doubt answer is awsme..but u can't ask the students to pairup or something like that...its your work to count...
otherwise i will say that just start the counting from one corner to last....:D

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

Nicely done..

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

nice solution..the same can actually be replicated by grouping 'n' number of students.
e.g take 4 students as a pair and find the total students%4..Then
total students/4 is used as the next input..
in simple terms n-ary division and find the decimal equiavlents
of the remainder in reverse form

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

Superb.....

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

Can anybody explain how come this is the quickest possible solution.

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

number rows * (number of column - 1) + number of rows in last column - number of empty seats

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

Or I will just check the attendance sheet ;) O(1) time

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

Is it possible to check the attendance in O(1) ? I guess we need to sequencely count number of P's (for present) in the array .and that can be done in 0(n) .

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

@Sandeep : xD

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

Ask first row people to count number of students in their respective column.... and sum all columns...

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

for each column, one student sitting at front start counting towards end and another student sitting at the end start counting the number of students towards front, they will meet at middle and add both and keep with one student... finally sum all column count.

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

Have each person stand up and find a partner.
If there is a single have him stand alone in the front of the class.
Assign one of the partners in each couple to remember the number 2 and have the other sit down.
Repeat this process and now have the person remember 4, then 8, then 16 and so forth until there is only one person standing.
Add 1 to the total if single person exists, and you have a O(lg(n)) solution.

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

Perhaps the best solution here.

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

Ask 1 student to go out of the class, then 2 students go out of the class, then 4 students, then 8 students... its a variation of binary search

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

obviously...

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

Tell the class to tell absent friends name

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

I think that we should know the capcity of the classroom, then just count the number of empty seat if most students show up

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

I think that we should know the capcity of the classroom, then just count the number of empty seat if most students show up

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

I think that we should know the capcity of the classroom, then just count the number of empty seat if most students show up

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

I think that we should know the capcity of the classroom, then just count the number of empty seat if most students show up

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

Ask every student to initialize value to: 1
Ask Every Nearest neighbour his no. and add his no. to yours both share the added no.
The highest at end is total no of students.

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

Ask every student to initialize value to: 1
Ask Every Nearest neighbour his no. and add his no. to yours both share the added no.
The highest at end is total no of students.

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

ASk students to stand like a Binary Tree. Total=2^n-1
If Last Level is not filled. Make them start a new Binary Tree..so on

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

ASk students to stand like a Binary Tree. Total=2^n-1
If Last Level is not filled. Make last level students only to start a new Binary Tree..so on

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

If there are N number of seats for M number of students ie, one for each students, which means M should be equal to N. Say if N-1 seats are occupied then one student is absent, if N-2, two students are absent and so on...

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

Just tell the class that on the day of the count you will give an exam where they have to write their name or else they get -100% on their final grade.

On the day of the count you subtract 0 from the the enrollment count. muhahahah!

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

Just tell the class that on the day of the count you will give an exam where they have to write their name or else they get -100% on their final grade.

On the day of the count you subtract 0 from the the enrollment count. muhahahah!

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

I would ask students to call out their roll numbers from last to first. ;) its takes only O(1) LOL. I am genius am i not?

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

Tell the students: "Anyone who is absent today raise their hand."
Then count the number of raised hands, lets name it p.
Then subtract p from the total number of students.
Then you will have :p

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

Any idea how to do it in O(1)??

Comment hidden because of low score. Click to expand.
-1
of 1 vote

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

i will ask for the last roll number..... :)

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.

### 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.