Bloomberg LP Interview Question for Financial Software Developers






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

This is a little tricky. Say switches nos are 1 to 100.
Here
after 1st round, all switches are ON (All were OFF, so toggling will make all ON)
after 2nd round, all switches divisible by 2 (switch no divisible by 2) are TOGGLED
after 3rd round, all switches divisible by 3 (switch no divisible by 3) are TOGGLED
after 4th round, all switches divisible by 4 (switch no divisible by 4) are TOGGLED
.......

In other way, we can see that all switches having ODD no of divisors are going on be ON, and all switches with EVEN no of Divisors are going to be OFF.
e.g. Switch No
1 == >> divisor is 1 (ODD count), will be ON
2 == >> divisors are 1, 2 (EVEN count), will be OFF
3 == >> divisors are 1,3 (EVEN count), will be OFF
4 == >> divisors are 1, 2, 4 (ODD count), will be ON

Now how to find out all nos from 1 to 100 having ODD no of divisors. This is again tricky. Only SQUARE Nos will have ODD no of divisors :-) so simple.
So nos with ODD divisor count are: 1,4,9,16,25,36,49,64,81,100

So answer is: Switches with SQUARED no will be ON after 100 rounds (All other will be OFF).

- Anurag Singh February 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hmmm... maybe I am missing something in the question. lets look at a smaller example 10 lights
1st round: all on
2nd round: divisible by 2 are set off --> [1,3,5,7,9] are on
3rd round: divisible by 3 are set on --> [1,3,5,7,9] are on
4th round: divisible by 3 are set off --> doesn't matter because none from the previous set are divisible by 4
so at the end of the day we should be left with just odd numbered lights? isn't it?

- GekkoGordan February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Actually question is not provided correctly. It is ctrying to say following:
While every round, TOGGLE the switches (If OFF, switch it ON, if ON, switch is OFF) which no is divisible by round No.

- Anurag Singh February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

okay, so its basically toggling, its not just setting. so previous states should matter

- GekkoGordan February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

e.g. for 10 switches:
after 1st round: ALL are ON
after 2nd round: 1,3,5,7,9 are ON
after 3rd round: 1,5,6,7 are ON (3,9 were ON, TOGGLE them)
after 4th round: 1,4,5,6,7,8 are ON (4,8 were was OFF, TOGGLE them)
after 5th round: 1,4,6,7,8,10 are ON (5 was ON, TOGGLE it, 10 was OFF, TOGGLE it)
after 6th round: 1,4,7,8,10 are ON
after 7th round: 1,4,8,10 are ON
after 8th round: 1,4,10 are ON
after 9th round: 1,4,9,10 are ON
after 10th round: 1,4,9 are ON

So for 10 switches, after 10 rounds, switch no 1,4 and 9 (SQUARED No) will be ON, others OFF.

- Anurag Singh February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

--

- Anurag Singh February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i.e lights that are toggled odd number of times are ON at the end.

so another perspective,
given 'n' unit blocks and you can arrange them in a rectangle (includes squares). what are the values of 'n' <= 100 that can form odd number of rectangles?

Soln: if you can form more than 2 rectangle with 'n' blocks then 'n' is not prime. And only "squares" have odd number of rectangles

- GekkoGordan February 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

well, the question is incorrectly stated so I've edited this post. Answers are provided by other folks

- GekkoGordan February 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this has been answered in the career cup interview questions pdf.....question 6.6

- February 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u mean the book?

- GekkoGordan February 04, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

yes..and the short answer is 10 lockers...the number of perfect squares between 1-100..because perfect squares have odd number of factors and hence toggled odd number of times

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

Why is 9 not on when it is a square. Does that mean only even no. squares will be on.

- Ashish February 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why is 9 not on when it is a square. Does that mean only even no. squares will be on.

- Ashish February 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

9 will be ON, I corrected in my previous example.

- Anurag Singh February 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

9 is on.

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

Lets do it for only 10 bulbs.

You can find the divisor of every number and if the number of divisior are odd then it will be on else off.
i.e
1= 1 = ODD
2=1,2 == EVEN
3= 1,3 = EVEN
4=1,2,4 ==EVEN
5 = 1,5= EVEN
6 = 1,2,3,6 = EVEN
7 = 1,7 = EVEN
8 = 1,2,4,8 = EVEN
9 = 1,3,9 = ODD

So you can see 1,4,9 are the numbers.. by looking at sequence,you can say that all perfect square numbers have ODD numbers of divisors.

So answer for original question is : 1, 4, 9, 16, 25, 36, 49, 64, 81,100

- Sanjay Kumar(Inventwheel.com) February 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry, 4 = 1,2,4 = ODD in my last comment !

- Sanjay Kumar (inventwheel.com) February 07, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Light Bulb 64 is on. The total number of bulbs which are on including #64 is 10.

First think who will operate each bulb, obviously person #2 will do all the even numbers, and say person #10 will operate all the bulbs that end in a zero. So who would operate for example bulb 48: Persons numbered: 1 & 48, 2 & 24, 3 & 16, 4 & 12, 6 & 8 ........ That is all the factors (numbers by which 48 is divisible) will be in pairs. This means that for every person who switches a bulb on there will be someone to switch it off. This will result in the bulb being back at it's original state.

So why aren't all the bulbs off? Think of bulb 36:- The factors are: 1 & 36, 2 & 13, 6 & 6 Well in this case whilst all the factors are in pairs the number 6 is paired with it's self. Clearly the sixth person will only flick the bulb once and so the pairs don't cancel. This is true of all the square numbers.

There are 10 square numbers between 1 and 100 (1, 4, 9, 16, 25, 36, 49, 64, 81 & 100) hence 10 bulbs remain on.

- dhaval0129 February 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The language is a little confusing, the third one turned every third on, who will take 3 off, no body, so it should be the third one flip the switch or some thing like that.

- ygfster March 16, 2012 | 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