**Question:**

How will you count the number of students in a classroom in quickest possible manner.

**Solution:**

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

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)

This is just using divide and conquer O(lg n)

POST YOUR OPINION IF YOU HAVE BETTER SOLUTION

## Click Here To add Comment

Your feedback is always appreciated.

I will try to reply to your queries as soon as time allows.

Please do not spam Spam comments will be deleted immediately upon our review.

Blogger Widgets