# Interview Questions

interview questions shared by candidates

## Interview Questions

### Vice President at Glassdoor was asked...

What is your management style? 37 AnswersThis is a great question. Would have been better if you have posted your response. After all, isn't the purpose of Glassdoor to provide the questions and responses -- for others to either learn or to avoid? Showing the response would be very helpful, especially if the responder got a job there My management style varies depending on the employee. I've found that people are different so a one-size fits all style doesn't work. Some people respond to aggressive goals; others don't thrive on pressure. Some people prefer frequent check-ins; others prefer clear direction up front and then giving them space to get their work done. Some general rules: * Focus on hiring smart people with great problem solving skills and good communication. * Take the time to explain the business value of the work they are assigned ensures motivation. * And most importantly, having compassion for each person - show the person you value them, show the person you care when things are hard, and invest your time in the person. Show More Responses I agree that management style depends upon the employee's competence and motivational stage for a task at hand.However,each individual will have a predominant natural style of leadership be it directive or supportive.Your own competence, experience and flexibilty help you to adapt to a particular situation. Management style depends on the manager thinking how he handle himself in worst situation before handling other.. i think management style depend on thinking of manager or mainly on coordination maintained by a manager between his team I have a feeling that management style solely hinges upon the manager's craft, capability and his response to an issue or a situation. Though ideally we talk of taking the team's point of view to move forward..but at the end of the day...it's the commander's whip that prevails upon and that everyone has to fall in line. I have a feeling that management style solely hinges upon the manager's craft, capability and his response to an issue or a situation. Though ideally we talk of taking the team's point of view to move forward..but at the end of the day...it's the commander's whip that prevails upon and that everyone has to fall in line. We have different Management Styles in an organization. There is no right or wrong style of management. We should adapt ourselves to use different management styles to handle different people. An Effective Manager, will first take time to understand the various personalities on his team and the next step is to use the right style to ensure you tap the right potential and mentor them to have a sucessful career. Management style will certainly differ depending on the situations however as a golden rule I should say whatever be the situation A manager should always make his team feel tht he is one among them. understanding the employes and making them wrk in their own way and making it ur style is really being wrth a manager and if u cn make employees wrk in ur style wats d point of a drawback People centriic, toyota concept of A3 problemsolving where many brains suggest different options and best solution leads to flawless achievement. And then questioning self betterment so that oetrganizational change keeps pace with environmental change and organization remains forever you ng a good manager would be one who varies his style depending on the type of situation or the nature of the employee. sometimes constant check ins and pressure application is required and sometimes giving space is a better option. Show More Responses its about how to keep everything under control and not to miss it and also its about being able to handle the problems , i do believe that its about having the required experince to do what you should do smartly hmm... if I'm a manager my management style would be a participative style. I believe that an organisation can best survive if their is minimal rate of attrition in the company i.e a good manager should be more employee centric rather than being a profit lover/seeker. Agood manager would be more patient and understanding. it's about how to keep everything under control and how to manage the employee. Be a model. it's depends on condition i just want perfection in work and good management makes a perfect team for work.... Management style means normal way of managing. This will depend on upbringing of manager, values & general style/environment at the organization. However, response to a particular situation may vary depending on criticality & urgency In management style we take some rule,and best community to give the perfect result for any problem.always maintain the level of that organization in market, also in society.But always take honesty and willing power to achieve destiny. because nothing is impossible. My Style Keep your subordinates mentally comfortable. Find out who is most suited for which type of job and try to assign accordingly. Set exemplary punishment if a person is found guilty and reward whoever deserves. Have some human touch. Don't go by management theories aplly common sense. Management style will certainly differ depending on the situations however as a golden rule I should say whatever be the situation A manager should always make sure that he is the main person for his team and he should do every single thing possible for him also for his team .. i will manage in such a way that people under me gets motivated, i will prove my involvement in enhancing company benefits as well the welfare of the people. WHEN PEOPLE UNDERSTAND OTHERS & MANAGE PEACEFULLY THIS THE WAY MANAGAMENT STYLE Show More Responses A GOOD MANAGEMENT STYLE IS TO MOTIVATE PEOPLE TO GIVE THEIR BEST I USE THE SKILLS OF MY SUBORDINATES TO MULTIPLY THEIR EFFICIENCY WITH SUFFICIENT SPACE TO PERFORM AND PROVE. nee the aswer for this question????????? management in my style is different coz management means we should be manage the thing in a proper way we should understand to each other by communication coordination and by cooperation. I try to adjust of my style of management to each situation,since part of my job is to assess both the best way to complete the project efficiently and the style of leadership that works best with current staff dynamic. just to explain the problems with the sub-ordinates and try to complete the work without any hard feelings of the juniors. The relational manager is interested in responding to the needs of the staffs as well as focusing on achieving the task. Relational manager are prepared to modify tasks if needed to cater for personal needs of individuals within the company or organisetion. Relational manager create an open communication environment where everyone develops trust and appreciation for each other. The leader’s aim is for the group to have positive memories that aid in personal development, self-confidence, and skills. I FIRMLY BELIEVE THAT AN EMPLOYER WANTS THE BEST INDIVIDUAL FOR THE POSITION. IN REFERENCE TO STYLE, I KNOW FROM EXPERIENCE THAT EVERY COMPANY HAS A SET OF GUIDE LINES PUT FORTH THAT EMPLOYEES ARE REQUIRED TO FOLLOW. THESE GUIDELINES ARE THERE FOR A REASON. MANAGEMENT IS RESPONSIBLE TO MAKE SURE THEY ARE ADHERED TO. A GOOD MANAGER SHOULD BE ABLE TO COMMUNICATE WITH HIS SUBORDINATES. A GOOD MANAGER SOULD BE ABLE TO KNOW WHEN HE SHOULD BE AGGRESSIVE,STERN, OR RELAXED WHEN A JOB NEEDS TO BE DONE. The best management style is when employees are lead by example and not by command. test Managing people is a skill you learn from listening, explaining expectations and working with your employees, teaching them what TEAM WORK is all about. Treat your employees with respect and they will respect you. They may not always like the choices they make, but they understand there are always consequences to their actions and e have to do are jobs, do it with respect. Show More Responses Being a good manager is about knowing your people. You can manage all day long, assign work out and be as directive as possible. But do you have respect from your team? Can they come to you and ask questions and feel at ease and confident in your response? Leading is the term I like to reference because a good leader supports their team and is uplifting. They give everyone an opportunity to advance if that is what they desire. People management is about your people and how you treat them. Don't be a friend but rather a mentor, someone they can look back at and say you were a positive influence in their life. For me the hardest part about leading is having that rock star employee who goes above and beyond, how do you continue to challenge that person if there is no room for advancement. People Management is my passion because I care about the people who work with me I don't just manage them. Management style is solely dependent on you and your approach to your team's success. People will follow you off a cliff if they know you genuinely care for them and their life goals. You cannot do this without spending time listening to them. So hire people smarter than you, then listen to them. This works every time! Being a good manager of people requires good insight, foresight, and good hindsight to make the former two attributes even more accurate. But most of all, a good manager doesn't seek to micromanage, but empower those who work for him. If you want to lead. You serve those who you want to follow. Without the attributes above, You cannot understand people, nor can you get them to follow your lead. A good manager should not seek to manage his people. He should seek to manage the daily operations of their jobs, by having the insight to know how their employees are feeling/performing (without data) , foresight to know where it will lead the team, and hindsight just to make sure there are better approaches to any given situation. These attributes requires immense experience with much self reflection. Unfortunately many managers would not agree with me. My management style is SITUATIONAL leadership. It depends on a situation you are in i.e. the urgency, importance, complexity, scope of work you are dealing with and the maturity of the team you are handling. - Autocratic will work in a situation where the team is new or immature and the urgency is very high. - Participative will work well in a situation when you have enough time for planning and have a mature team from which you are expecting good critics or feedback based on their knowledge base. - Delegative style works well when you are leading a mature and senior people in your team and the job is well known or at least well defined and roles are pretty clear. That is when the team is working under "Performing" stage. |

25 horses, 5 race tracks. How many races you have to run to select top 5 horses. 51 Answers7 Races First race all 25 in groups for 5 to figure out top 3 in each group. (15 left) Call them A1 B1 C1 D1 E1 A2 B2 C2 D2 E2 A3 B3 C3 D3 E3 Here A1 is faster than A2. A2 is faster than A3. The same applies for the rest of the groups. Now race A1, B1 C1 D1 E1 Lets say the order of the horses according to ranking was A1, B1,C1,D1,E1 So A1 is No 1 Now A1 is faster than B1 and B1 is faster than C1. So we can get rid of the entire D and E groups 9 horses remaining Also A1 is faster than B1 and B1 is faster than C1. So we can get rid of C2 and C3 7 horses remaining A1 is faster than B1. B1 is faster than B2. get rid of B3 6 horses remaining Out of these, We know A1 is the fastest. So now race A2, A3, B1,B2,C1 to figure out No2 and No3 positions One race is the answer Why 1? Show More Responses because, the top 5 are the fastest right ? so you run one race and take the best five times. It's a trick question to see if you'll make a mountain out of a mole hill. The first question to ask to clarify is: how many horses can fit in one track? Technically, one track can be used for all 25 horses, but this is too crowded for an efficient race. Let's say track size is not a factor, then, you need 1 race. Without overcomplicating things - the answer is 1 race. All other answers are based on dissecting the problem into, imo, unnecessary details. There is no mention of the capacity of each race track or number of gates available etc. Even if there are less than 25 gates available at a track, I'd say fetch enough number of gates so you can find the outcome with single race. This isn't a trick question. Normally this question has a track limit of 5 horses. I agree with Anuradha's answer. Anuradha's solution still has problems. (Even if we go with Anuradha's assumptions that you can only race one horse per track, and also assuming that we don't have a stopwatch and must compare horses placing positions) What if the fastest five horses are A1, B1, C1, D1, and E1 ? In Anuradha's second step, he elminates two of the fastest horses (D1 and E1) . He's assuming that A2, B2, or some of the other horses from the other heats are faster, but he hasn't actually tested to see if that is true. @anuradha: I think there are 2 problems: 1. How do you know A4 is not faster than B1 .... Suppose A1,A2,A3,A4,A5 are the fastest. 2. Using the logic posted we can get the answer in 6 races, 5 races for finding A1,B1,C1,D1,E1 and 1 race to find the ranking. Assuming 1 track for 1 horse then it need 5 races to select top 5 horses. Each race for 5 horses and count the time for each race. The top 5 fastest horses are the top 5 horses. 2 max: top 4 from first race, if 5th is a tie, then two, or else just one. 5 6 Show More Responses You guys are not doing CS! 10 runs is my answer. 1. randomize 5 groups, each of 5 horses 2. rank them within each group, I will use Anuradha's notation (5 races) 3. pick the best of each group, race to figure the 1st place, call it A1 (1 race) It should be clear, it wins all times, every one lost once. 4. remove it. substitute 2nd best in. repeat 3 (in my eg. A2,B1,C1,D1,E1) now you have second place. keep going, you get the first 5 and ranking! So, 5+5=10 races in total. The answer is 9. Assuming: - There's no time measuring (stopwatch), just relative places. - The horses perform consistently. - A maximum of 5 horses per race. First we need 5 races (A to E) to get relative scores for all 25 horses. Let's take a worst scenario: the list was already ordered (A1 fastest and E5 slowest), so race A contained the top 5. The 6th race would be the winners of the 5 races (A1, B1, C1, D1, E1), and would give A1 as the fastest of all. This would also mean that some horses can be excluded (only 4 more places to fill): B5 C4, C5 D3, D4, D5 E2, E3, E4, E5 For the 7th race, A2 would replace A1, and A2 would be appointed as the runner-up (of all). We also can exclude some more (only 3 more places to fill): B4 C3 D2 E1 For the 8th race, A3 would replace A2, but as E1 has been excluded, we got a vacancy. Let's add C2 for worst case scenario. The winner would be A3, and we can exclude more horses (only 2 more places to fill): B3 C2 D1 At this point there're only 5 horses who have not yet been classified or excluded, so the winner and runner-up of the 9th race would give 4th and 5th overall. To Patrick: I had to slightly modify your almost correct solution and got 10 races. You has an excellent idea to remove subset of candidates after final selection of the i-th horse, and my modifications are not an essential ones. Actually it is necessary to fix two small things: 1. get rid off the suggestion about the ordered list To avoid this suggestion I would rename groups from the fastest A to the slowest E with order by 1st horse after final selection of the i-th horse. So after race #6 we have order: A1, B1, C1, D1, E1, but there is no suggestion that all A are better than all B and so on. And after every race #7, #8, #9 we have to rename groups. With this modification your method works fine until final selection of horse #5 2. Without this suggestion you need race #10 to find the last 5th horse. To test both methods you may use 25 randomly selected integers and select the 5 minimal or maximum ones. I can't prove that 10 is the minimum number of required tests, but it looks very convincing. Thank you. Maybe Ziqi Dai also meant the same method, but it was difficult to understand without a couple of details. To Leo, I checked some random sequences with a spreadsheet, and all the remaining (not placed or excluded) horses run in the 9th race, so there's no need for a 10th race. Sometimes there're only 4 or even 3 horses left in the 9th race. I didn't check every possibility, but there was no indication a 10th was ever necessary. This answer is 1 regardless of track. If it can fit all 25 then you only need one race. If you make the assumption that only 5 can race at a time then you put 5 on each track and start the race on each track at the same time. Either way, the fastest 5 horses win. Using complex math on this is pointless since a pragmatic approach is available. @ Anuradha -- this is a great solution to the wrong problem! The classic problem is to find the THREE fastest, and that's what your solution is. However, the question posed in this thread is (likely incorrectly quoted from the interview) to find the FIVE fastest of the group. why would you make an assumption that makes this more difficult? I mean given this is an IQ test of sorts, making it harder than stated is........ Attention to details, Anuradha! You're answer would've been correct had the question asked for top 3 horses. This is like merge sort. In the first 5 races (when we run 5 horses per race) we get 5 sorted sublists. Each sub-list contains 5 horses sorted by their relative speeds within that sub-list. Now just merge these 5 sorted sublists to get your answer. Every "merge" means 1 race to find the fastest horse from the front of these 5 sorted sublists. To summarize: 1. Creating 5 sorted sublists of 5 horses each = 5 races 2. Getting fastest horse = 1st round of merge = 1 race 3. Getting second horse = 2nd round of merge = 1 more race 4. and so on... Show More Responses Why is this harder than having five races with five horses, recording the times of each horse, and sorting the list of observed values to get the top 3? it is seven race 7 full explanation; http://www.programmerinterview.com/index.php/puzzles/25-horses-3-fastest-5-races-puzzle/ 1 For 3 fastest horses no doubt the answer is 7 but for 5 fastest I worked it out to be 9. And pretty sure too 1 only if you can do good flow control and horse will start with different time / space out based on best estimate. It is kind of feeding the horse to the gate. Simply 5 races only, i.e. 5 horses in 5 race tracks per race. Finally, select top 5 horses by best fastest timing at finish line after 5 races. As a BA, the answer I would give is: We don't yet have enough information to provide a solution. There is critical information missing that could affect the solution. And flushing out all the critical factors of the problem are one of the most important responsibilities of the BA. As a BA, it is very important to NOT start building solutions to problems that you don't yet fully understand. Actually, it's one of the biggest mistakes inexperienced BAs make: solving the wrong problem because they rushed to solutions and did not fully investigate and understand the problem! Once they're committed to the wrong problem, they end up with a beautifully done inadequate solution. 5 races, because you can fit 5 horses in 1 race and there are 25 horses. You just note the timings of each horse and compare them after all the races are done. That way, you won't have to arrange more than 5 races and stopwatch is a common tool for every phone!!! First of all guys, you guys are making critical mistakes. You assume we have a timer but that would make it too easy, right? I'm just assuming that 5 horses a track and no timer. So I have two potential solutions: 1. You could always just race them all at the same time on 5 tracks...but that'll be too easy. Then there's my solution: --------------------------------------- First, group all the horses into five groups of five. It doesn't matter which horse goes into which group, it honestly doesn't matter. Then, race all the horse in one groups against each other. It helps to name them A-E(Group name) and the number place they came in (ex: 1st place a group would be A1). So now we have A1 to A5 and B1 to B5 and so on until E5. Then race all the 1s against each other. You should get something like A1, C1, B1, E1, D1 and then you should arrange their groups in collumns from left to right based on that race (1st on left, 5th on right). Here is where it starts getting complicated, so I will just assume it is A1 fastest in that race and E1 slowest and so on just for simplicity. So so far this is 6 races. Get E1 and race them against D2-5. You can ignore E2-5 because no matter what they can never be in the top 5 because A1, B1, C1, and D1 is the fastest of their groups and you know that the fastest five can come from those groups but not E2-5 because E1 is the slowest of the 1's and there's no way those horses can be in the top five. SO just throw them away. Since there are four spots available max you race the slowest four of the D which happens to be D2-5. Get the place numbers and arrange them. EX: D1 D2 E1 D3 D4 --- D5 E1 can be anywhere based on E1's speed but you immediately want to discard the D5. You might be saying, "Hey, why can't we discard anything below D2 since A1 and B1 and C1 are all faster than D1 and E1?" But...you could be unlucky and have A2-5 and B2-5 and C2-5 be all dirt slow. So just keep them for now. So the rule now is to keep all the horses that are in the top 5 and discard the rest until you get to A, when you know, "Oh, A1 has to be the fastest horse." 7 races. So we have our list above just for examples. Next you want to race D4 against C5 to see if our group can EVEN pass the C's, cause we might get super unlucky and see that C1-5 is faster than D1...if D4 loses in 5th place we just throw this all away and our new list becomes: C1 C2 C3 C4 C5 But otherwise we'll just assume that our D4 luckily got to 3rd place. It becomes: C1 - Our group can go anywhere inside the lines so race them again C2 minus D4 since its in 3rd place to see where they go. Let's assume we got SUPER lucky and C2 became last place in that race. - C3 C4 C5 8 races. We raced this group at that time and left out D4 because D4's fate was already decided: D1 D2 E1 D3 C2 It turnes into this: C1 - D1 D2 The single dash indicates where our new group was spliced, ofc the triple E1 dash lines show where the cutoff is, so discard everything under the line. D3 -(---) C2 D4 C5 9 races. Kay, so now we have the five fastest in the E, D, and C groups. Now continue with the B groups and let's say that our D3 passed B4 only... It becomes: B1 B2 - With our top five so far group racing against B4 B3 - D3 B4 B5 10 races. And then with another race you get this with lets say...only our top two making it through with B3 getting ironically first place: B1 B2 B3 C1 D1 --- D2 E1 Yep...E1 got kicked out. Aw well. SO NOW our to group D3 is the group above the triple dash marks. B4 B5 11 races. Now we're up against the A group. Assume that they are all wusses and that our D2 beat all of them except for A1. So we got lucky and the new lineup is this: A1 B1 B2 B3 C1 --- It was inevitable that A1 would become first but now this is how you do it! D1 D2 A2 A3 A4 A5 12 races/13 if our B1 didn't beat all of the other A's on the first try. Conclusion: 5 races (initial races)+1 race(for initial group leader ranking)+1 races(E-->D)+2 races(D-->C)+2 races(C-->B)+2 races(B-->A) =13 races/10 races if you get insanely lucky and have all our previous groups beat all the #2s of the groups. Show More Responses Oh nvm ignore that it was all crushed into one place with no spaces...I'll stick a better one later. The answer is 8 races assuming that you can fit only one horse on one track. Divide the group into 5 horses. In five races we can find the 5 fastest horses in the 5 groups. The 6th race is among the top 5 fastest horses. The top three fastest horses in the 6th race are faster than the horses in the group of the 4th and the 5th fastest horse. The horse that came third in the 6th race may or may not be faster that the horses in the group of the fastest and the send fastest horse. To determine that, we hold 2 more races. So 6+2 = 8 races is what I think is the correct answer ****************ANSWER -- 3 RACES.************* Given : 25 horses, 5 tracks Assuming : 5 horses to a track Five groups of 5 horses for each track (5 tracks, tracks ABCDE, each track with horses labeled "X#") First race allows you to find out the top 5 horses (however this isnt the true top 5) [A1,B1,C1,D1,E1] Second race the top horse is discovered (lets say its A1) Now you have to find out if B1 is better than A2, B2 is better than C1, etc. (each predecessor of each winner) We know that B1 is better than [(CDE)1] Third race we have A2,B1,B2,C1,D1 Conclusion : If both of the predecessors are NOT last place, then we have our answer at race 3 by taking the top 4 to be the bottom 4 of the top 5. Otherwise, repeat this process one more time to find the 5th placed horse. Ans is 14 Patrick gets the right number but his logic is not the most efficient. Initially follow the standard procedure and race 5 groups of 5 (races 1-5) and then race the winners (race 6). The winner is the fastest overall. Now name the groups with the horses in the winners group A1,A2,A3,A4,A5, the first four horses in the runner-ups group B2,B3,B4,B5, the first three horses in the third group C3, C4, C5 down to E5 for the winning horse from the slowest group. The numbers indicate the highest possible position a horse could attain (i.e. C4 is definitely slower than C3, B2 and A1 but may be slower than several others). The rest of the horses are eliminated and so don't need to be labeled. Now race (race 7) the horses labeled 2 or 3 (there are 5 - A2,A3, B2, B3, C3) The top two are second and third overall and the loser is eliminated. You can eliminate a total of 5 or 6 horses - those known to be slower than the fourth or fifth place finisher and any two positions slower than the third place finisher in race 7. There aren't that many options here so you can just inventory all the possibilities if you wish. At this point you have a maximum of 7 horses for the remaining two positions You just race any 5 (race 8) to eliminate at least 3 and race the rest (race 9) to get the fourth and fifth fastest overall. If you choose all the potential fourth place finishers in race you may not need race 9. As noted elsewhere Anuradha gets the right answer to a different question than the one asked. I have stepped among a lot of smart folks here. Maybe even several analyst's. So here it goes. I am looking at this as who the question is coming from and for what. A Business Operations Analyst for Google. Everyone is so focused on answering the question based on assumptions. Ie. That every horse and rider are at their best condition and that every track is exactly the same. That you are running all the races in the same day and that horses, riders, and tracks dont change. Horses and riders get tired, not to mention the possibility of injuries, and track conditions can change so forth and so on. So to me. In order to (analyze) to get the best possible answer. I would start by asking questions and not assuming. The more information you have leads to the best possible answer. Guys think as a programmer, (mind my language and grammar) algorithm would be of these steps ->group the horses (5 horses each) -> get the best runner of each group (five races) -> store the horses in winning orders to five stacks (a,b,c,d,e) ->until the top 5 are found, repeat ->race all the 5 on top of the stack ->pop the winner from its stack and store in top five that all, now lets see how it will work. lets have 5 horses per group and group them as a,b,c,d,e. 1=a1 a2 a3 a4 a5 a1 (winner) 2=b1 b2 b3 b4 b5 b1 3=c1 c2 c3 c4 c5 c1 4=d1 d2 d3 d4 d5 d1 5=e1 e2 e3 e4 e5 e1 now we have best of each group, let them race 6=a1 b1 c1 d1 e1 a1 for every winner get the best candidate for the group, and race again, until top 5 are found 7=a2 b1 c1 d1 e1 a2 8=a3 b1 c1 d1 e1 a3 9=a4 b1 c1 d1 e1 a4 10.a5 b1 c1 d1 e1 a5 for any scenario just get the so the ten races. its like finding five highest numbers from 25 numbers, when you can only compare 5 at a time. Answer- 7 Races Give names H1....H25 Divide into 5 groups as 5 can run at a time H1, H6 , H11, H16, H21 are fastest in there groups Now we can remove last two from each groups as we need fastest 3 now we left with 15 horses 6th Race- between all fastest in groups After 6th Race H1> H6 > H11> H16,>H21 Now H21 was fastest in group but is 5th in 6th race so H22 and H23 who already slower than H21 can't be in first 3 Same thing applied for H17 and H18 as H16 was fastest in group race but 4th in 6th race Same applied for H12 and H13 as H11 was fastest in group race but 3rd in 6th race Already three horses are faster than H16 and H21 so they both also can be rules out Now we left with H1, H2, H3,H6, H7, H8 and H11 But H8 is slower than H7 and H7 is slower than H6 in group race and we have H1 on top already so H8 also can't be in fastest 3 Now we left with H1, H2, H3,H6, H7, H11 H1 we know is fastest..so lets 7th race between H2, H3, H6, H7 and H11 and find the other two After 7th race you will get fastest 3 Make a group of 5 horses per track and race them all at once. The winners of each track totals to "the top 5" ! The answer is 7. Assuming: - There's no time measuring (stopwatch), just relative places. - The horses perform consistently. - A maximum of 5 horses per race. Race r1: A1 A2 A3 A4 A5 (By order of winners) Race r2: B1 B2 B3 B4 B5 Race r3: C1 C2 C3 C4 C5 Race r4: D1 D2 D3 D4 D5 Race r5: E1 E2 E3 E4 E5 Race r6: A1 B1 C1 D1 E1 (rename R1 R2 R3 R4 R5) Here comes the tricky race. From race 6, we already know the ranks. As a demonstration, assume R1 = A1, R2 = B1, R3 = C1, R4 = D1, R5 = E1. Then: 1) D1 D2 D3 D4 D5, E1 E2 E3 E4 E5 are out of the contest. Because D1 and E1 are ranked 4th and 5th in a race. 2) C2 C3 C4 C5 are out of the contest. Because two horses already are faster than C1 ==> 3 horses are already faster than C2 C3 C4 C5. 3) B3 B4 B5 are out of the contest. Because one horse already faster than B1 ==> 3 horses already faster than B3 B4 B5. Remaining potential horses are: A1 A2 A3 B1 B2 C1. Here, A1 is redundant because we already know it is fastest. Race 7: A2 A3 B1 B2 C1. The top 2 will be added to A1 to be the fastest three. Show More Responses Take a look at previous horse race statistics from horse newspapers. Make your analytic and you have your top 5 horses without any new race :) It will take min 9 race not 7: first five race and find top 3 @ every slot now total race=5; one race between first five, now we find top 3 and take 2nd and 3rd from the race as 1st is declared. race=1; 1 race between 2nd finisher of all slot and take 2 from them , race=1; 1 race between 3rd finisher of all slot and take top finisher, race=1; now we have race between 5 horses(2+2+1) and find 2nd and 3rd; so total no of races= 5+1+1+1+1=9 ; I have grouped them in 5 groups. See the groups below. I have also ranked them in the order of the wins. So for e.g. in the first group, 1st horse came first, 2nd horse came second and so on In the second group 6th horse came first, 7th horse came second and so on. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 After the first five races, there will be two more races So the sixth race will be among the horses below (who were first in the previous races) and I have ranked them in the same order in the 6th race 1 6 11 16 21 - - So 1st horse came first, 6th horse came second and so on. Now for the 7th race, we will take the winner of the 5th race and make him compete against the first four winners of the 6 the race. So it will be something like this and I ranked them in the same order for the 7th race. 1 6 11 16 26 - So from 7 races it will is very clear that the fastest four horses are 1 6 11 16. Now, only 21 and 26 are the contenders for the fifth position, based on their timings in their respective races (6th and 7th ones), we can decide which one is faster between the two. So in total , we would need 7 races. The question is not a good one! Let those horses be marked X1~X25. First divide them into 5 groups X1~X5, X6~X10, .... Assume the first X1, X6, X11, X16, X21 are the fast ones in each group after the first round. Also, X2 > X3, X6>X7, during the first round. We then, during the 2nd round, form the first group with those fastest from each group in the first round. Assuming that X1 > X6 > X11 > X16 > X21 after the first try of the 2nd round, we will then have X2, X3, X6, X7, X11 to form a new group and determine which are fastest 2 in this new group. Nevertheless, during the 2nd try of 2nd round, it can happen that X3 > X2 or X11 > X6. The inference fails all the relation set in the previous try. ( that the X2 > X3 ,after the first round, and X6 > X11, after the first try of 2nd round). It would be better to change all those horses to be boxes carrying different integer value. You want to sort those boxes to find which carrying the largest 3 numbers and, at any time, you can only open 5 boxes to inspect . You cannot mark the content of boxes but you can put down the relation between boxes during the inspection. Then, the number of inspections needed to find boxes with the largest 3 number will be 7# This seems like a simple answer, but I'm pretty sure it's 9. Race 5 groups of 5, then race all the 3rd place, then the winning 3rd races the seconds, then you have either have five firsts and two seconds left or 5 firsts a second and a third left from the original racing groups. Worst case scenario you have one more race of three ones and two twos or two ones and the 2nd and third place to find the fastest there out of that last group. 9 races. So driving down the road I figured out I should have started from the top after the first five races. Then worst case scenario you run three more races to find out the top three. 11111, 21111, 31111. Damn. Six races, six groups. First group will have five horses, the 5 others groups will have only 4 horses. The winner of the first group of 5 horses will pass to the second race, then the winner of the second race will pass to the third race and so on, bay the end of the 6 race you will have top 5 horses. 25 horses, 5 race tracks. How many races you have to run to select top 5 horses. Solution: http://codinginterviewquestionsans.blogspot.in/2017/07/25-horses-5-tracks-5-fastest-horses.html Step 1: First, we group the horses into groups of 5 and race each group in the race course. This gives us 5 races. W11 W12 W13 W14 W15 W21 W22 W23 W24 W25 W31 W32 W33 W34 W35 W41 W42 W43 W44 W45 W51 W52 W53 W54 W55 Step 2:we race the 5 level 1 winners(w11,w21,w31,w41,w51) and assume winning order of this race is w11,w21,w31,w41,w51 (THIS IS 6TH RACE) Step 3: BECAUSE WE NEED TOP 5 AND W51 HAS COME 5TH Position that is the reason we don't need to consider W52 W53 W54 W55 now we have W11 W12 W13 W14 W15 W21 W22 W23 W24 W25 W31 W32 W33 W34 W35 W41 W42 W43 W44 W45 W51 Step 4: because we need top 5 then dont need W25 W34 W35 W43 W44 W45 now we have W11 W12 W13 W14 W15 W21 W22 W23 W24 W31 W32 W33 W41 W42 W51 Step 5: top 1 is already achieved which is W11(winner of 6th race) remaining are X W12 W13 W14 W15 W21 W22 W23 W24 W31 W32 W33 W41 W42 W51 Step 6: candidates for 5th position: W51 W42 W33 W24 W15. 1 RACE TO GET 5TH POSITION (this is 7th race) remaining are X W12 W13 W14 W21 W22 W23 W31 W32 W41 Step 7: candidates for 4th position: W41 W32 W23 W14. 1 race to get 4th position ((this is 8th race) X W12 W13 W21 W22 W31 Step 8: candidates for 2nd and 3rd position: W12 W13 W21 W22 W31. 1 race to get 2nd and 3rd position ((this is 9th race) Hence answer is 9 races. |

### Operations Associate at Zocdoc was asked...

What is your least favorite thing about humanity? 30 AnswersPEOPLE AT WAR inane interview questions Politicians. Show More Responses It disappears along with your souls if you die before recovering. The people. Humans are the only animals who kill others for fun and recreation. I don't see many human bbqs on sale. The kardashians The capacity for apathy, ( I would try to make a change-but I really don't care). The lack of it! Seeing our reflection in the mirror & asking ourselves this question would obviously be our least favourite thing. The "IN"that usually comes before the humanity part. not knowing why... cruelty Show More Responses Politics Answering stupid questions from moronic interviewers. Ignorance, and prejudice arising from that ignorance. It is responsible for so many negative things (wars, etc). Additionally, individuals less able to question their beliefs and assumptions about something (i.e. choose to remain ignorant, continue a prejudice, etc.) have been found to be less able to deal with change. This translates into the work environment in the following ways: - Training becomes more difficult - Changes in office practices (eg a move from set desks to "hot-desking" are rejected (despite longitudinal [i.e. studies over time] evidence indicating it is better), and can actually be a bit traumatic for people not able to accept change. - New technology less likely to be accepted. --> Basically, individuals are more difficult to train (or reject training), less likely to try to upskill, and do not sit well with the natural changes that would occur in an org over time. Sorry for the complex answer! :P The lack of accountability of an individual once they associate themselves in a group Backbiting Everything Current definition of humanity itself. Job interviews The people. The humans. Show More Responses Life. No humanity action if we die Fake Smile The idea and perception that there is innate negativity in human that is more powerful than the positivity that resides hidden within us. We always ask questions about ourselves to other people. Stupidity Ugh, like, you know, the 1%? Is that what you want to hear? Dishonesty |

### Software Engineer at Facebook was asked...

You have two lightbulbs and a 100-storey building. You want to find the floor at which the bulbs will break when dropped. Find the floor using the least number of drops. 36 AnswersStart moving up in increments of 10 floors and dropping the bulb until it breaks (ie: drop from floor 10, if it doesn't break, drop from floor 20, etc.). Once the bulb breaks, move down to the floor above the last floor it broke on and start moving up floors in increments of one until the second bulb breaks. This results in a worst case scenario of 19 drops. Surely a binary search method would be more efficient i.e. starting at 50 and either going up or down 25 floors based on if it breaks or not. If you do a binary search, what happens if it breaks at floors 50 and 25? Show More Responses Do you know what a binary search is? You drop it from floor 12 next. If it breaks, you know it breaks between floors 12 and 1, inclusive. If it doesn't, you know it breaks between floors 13 and 25, inclusive. The main principle of binary search is that with each step you reduce your search space in half. Now your search space consists of only 12 floors. Wow, I want to get asked such a question in an interview! >>you drop it from floor 12 next... if you broke it on 50 and 25... you are out of luck and out of bulbs... 19 drops is not the best worst case scenario... imagine trying floor 16, if it breaks, you try 1 - 15 and thats 16 tries. if it doesn't break, then try floor 31 and if it breaks, then try 17 - 30 (so 16 tries, including the try on floor 16). And on and on (45, 58, 70, 81, 91, 100). If you reach 91, you'll have tried 7 floors so far and if it doesn't break, then there's 9 more tries to get to 100 (thus 16 in the worst case) Even a drop from the ceiling of 1st floor, a simple light bulb will break. thats what i think It's a light bulb. It will break when dropped from the 2nd floor. Drop it there then go to the first floor, hold it over your head and drop it. first do a binary search (agressive first step - fast) with 1 bulb. when first breaks, you know X(last but one fall - success) and Y(last fall - failure). now do a linear search starting from X(conservative but accurate second step - slow). complexity = in between logN and N. Use Binary search starting with the middle 50 The complexity of binary search is logN . So it will be log(100) < 7. Based on my experience, I think it will be floor 1 itself . Drop from 1st floor. If it didn't break, drop the same bulb from 2nd. If it still didn't break, drop the same bulb from 3rd... repeat as necessary. Only one light bulb required :) Yes, but doing each floor, that will give you the most drops -- question relates to optimizing for "least" number of drops -- I didn't think about being able to re-use the bulbs...that obviously is helpful. Maybe a fibonaci sequence once you determine a "break" floor and a "non-break" floor. I'd probably fail completely at coding it...knowledge of optimization and prediction theory would certainly be useful. Let f(m,k) be number of tries for m lamps and k floors. Obviously f(1,k)=k. let f(2,k) be s. k<=(s-1)+(s-2)...(1) =s(s-1)/2. Therefore f(2,100)=15. Show More Responses Actually, 16 is not the optimal, nor is 15; you can do it in 14. Here is one solution (there are at least 5 other equivalents): * Drop first bulb at 14th, 27th, 39th, 50th, 60th, 69th, 78th, 85th, 91st, 96th, and (optionally) 100th until it breaks. * Go to the highest floor where the first bulb didn't break. * Repeatedly go up one floor and drop the second bulb. When it breaks, you have your answer. Why is 14 optimal? Since you are decrementing each time, you want (n) such that sum(1..n) barely reaches 100. The answer is n=14. Generally, if the number of floors is (f), the lowest number of drops is ceil((sqrt(8*f+1)-1)/2). This is the best worst-case scenario. An interesting related question is what gives the lowest expected number of drops. And no, I could not have gotten this in an interview. In theory, use one bulb to determine an interval, and use the second bulb for a linear search within the interval. The solution that decreases the interval by one for each trial is quite clever. In practice, however, take the nature of the problem into account: Start on the first floor and move up by one floor. That's the answer I would be looking for. Start with bulb 1 and drop it from floor 2. Doesnt break? then floor 4 Doesnt break? keep dropping the same bulb moving even number of floors all the way upto floor 100. If on some even floor the bulb breaks drop the second bulb from the odd floor below the even floor, to detect if its the even or the odd floor that breaks the bulb Best case detection: 2 tries (first bulb breaks on 2nd floor, second bulb breaks on 1st floor) Worst case: 51 tries (the fist bulb breaks at 100 and second bulb breaks or does not break at 99th floor.. ) Go to the 100th floor and drop the first bulb. It WILL break. Done, 1 drop. It doesnt say whats the lowest floor it will break at, just at what floor will it break with least drops. Thus floor 100. Alright guys...you have two light bulbs. ...the second one has to be used for linear search, let the worst case number of items to be searched be x, then your interval will also have to be x, which will result a worst case of 100/x drops for the first light bulb. So now you are just trying to minimize n=100/x+x, find n'=0 when x=19...the candidate's answer is correct. I meant...x=10. and n=19. 0 drops, 1 bulb......stop thinking like computer nerds. Use physics or an engineering mindset. They didn't prohibit the use of any tools. Grab a scale, figure out force req'd to fracture bulb. Calculate acceleration due to gravity adjusting for air resistance/barometric pressure at location (trivial for anyone who took a 1yr physics course). Figure out how many meters up you need to be based on the req'd acceleration. Done.... @Rich: I am sure they were hoping for you to give them a computing answer since they don't do physics, and rather do computer science. mer's answer is correct: 14. Let F(s, n) be the optimal worst-case number drops for s stories and n bulbs. Suppose we drop at floor f, constituting one drop. If it breaks, we must make up to F(f-1, n-1) drops. If it doesn't break, we must make up to F(s-f, n) drops. Thus, for a given floor f, we have up to 1 + max { F(f-1, n-1), F(s-f, n) } drops. Optimizing over f: F(s, n) = 1 + min{ max { F(f-1, n-1), F(s-f, n) } for f in 1..s} Using the appropriate base cases, we have F(100, 2) = 14, as mer has given. Another way to think about it is in terms of decision trees. We want to construct a binary decision tree with leaf nodes for floors 1..100, and at most one "left" turn per path from root to leaf. To minimize the height of the tree, we want to reduce the variance in the length of each root-to-leaf path. This suggest we try dropping the first bulb at floors of the form: a, a-1, a-2, .. a-b, where the sum a + (a-1) + .. + (a-b) is equal to or barely over 100, so that determining almost any floor (possibly excluding the top few) takes a drops. Using this approach, we get the sequence of drops that mer has suggested. Well done @mer I have seen this question posed many ways, and that is the best answer I have ever seen. Sure hope I get asked this one now Show More Responses 14 In my experience light bulbs break when dropped from any height above 3 feet nice explanation from http://www.programmerinterview.com/index.php/puzzles/2-eggs-100-floors-puzzle/ Depends on how accurate u want to be. If i want exact answer, drop one from fifty, if it breaks start from first floor woth the remaining bulb. If it does not break, then start from fifty first florr. u will iterate fifty times as worst case. If u want a approximate answer, u can do binary way with give or take twenty five floors. Step over based on accuracy needed. You are all ignoring valuable information in this question. We are talking lightbulb, not bowling ball, and building, not step ladder. The bulb will almost certainly break by being dropped from the second floor (assuming US numbering conventions). The chance of it surviving a 3rd floor drop are miniscule, but not zero. The chance of a 4th floor drop, even less. Therefore, drop it from the 3rd floor first. If it breaks, go to the second floor and try. If that breaks you know the answer is 2. If it by some miracle doesn't break from the 3rd floor drop, the answer is 4, but take the elevator up one floor and drop it just to see. Rinse and repeat to 5, but since it will have already broken, go out and grab a beer, and tell your friends how much fun you just had. n*(n+1)/2 = 100. n approx = 14. In worst case u can figure it out in 14 drops. 14th, 27th, 39th, 50th, 60th, 69th, 78th, 85th, 91st, 96th, and (optionally) 100th until it breaks. I believe the number sequence should be: 14, 27, 39, 50, 60, 69, ** 77, 84, 90, 95, 99 **. The 9 floor gap between floor 69 and 78 would result in 8+8 = 16 drops worst case. Easy. Answer is zero. You don't need a test to find out that a lightbulb is going to break, even when you drop it from the first floor, because it's made of glass. BigO(100/X + X-1), Where X is the number of floors. 100/X calculates the dropping times to break the first one and X-1 is the additional maximum overhead to break the second one starting from the previous dropping floor to the floor the previous bulb was broken. If you solve the derivative of the above equation equal to zero, the optimal solution becomes 9.9 ~= 10 . Worst case = 100/10 + 10 -1 = 19 If its a glass bulb it will break from a 2ft height...i wont even care climbing any floors to check. Show More Responses Once you break the first light bulb, you are FORCED to start at the highest safe floor + 1 (i.e. highest floor that you safely dropped bulb #1 from) and drop bulb #2 one floor at a time, moving upward. Therefore, the algorithm for the first light bulb is critical (cuz once it breaks you are counting by 1's upward). Binary search starts at the 50th floor ==> max # drops = 50 Choosing fixed increments rather than binary search, e.g. start at 10, increment by 10, yields better results ==> 25 The ideal solution is 14 drops ==> Start at 14, increment by 14 each step until it breaks (leaving for the reader why 14 is optimal). It doesn't matter what floor you are on to make a bulb break. Doesn't it matter how high off the floor the bulb is dropped. If I am on the 5th floor and the bulb is sitting on the floor of the 5th floor, how high off of that 5th floor do I need to drop it before it breaks. This is a misleading question. The question doesn't say that you will drop the bulb out the window. Drop both from eye level. Both will break, and I answered the question without even climbing one stair. Efficiency isn't always about math..Common sense |

### People Analyst at Google was asked...

how many basketball can you fit in this room 24 AnswersDepends ... should we assume they're inflated? Determine the volume of the room. For example if the room is 10ftx10ftx10ft the volume would be 1000ft cubed. The average mens basketball has a diameter of 25cm. There is approximately 30cm in a foot. Therefor you could fit one inflated basketball in a 1 foot cubed space. Therefor you could fit 1000 inflated basketballs inside a room with a volume of 1000 ft cubed. If we can deflate the basketballs and flatten them down to one inch thick, this would allow us to place 12 flattened basketballs in a 1 foot cubed space. Therefore you could fit 12,000 basketballs in a room with a volume of 1000 ft cubed. It would be more complicated depending on the shape of the room but the process for figuring out the solution would be the same. Actually, what you want to do is figure out the ratio of the diameter of the basketball to a full foot. Basketballs are 10 inches, and 10 is .8333 of 12. Remember that, then figure out the volume of the room by multiplying height by width by length---divide this number by .8333. BAM. So, if its a room of 12 x 10 x 8, you get a volume of 960. Divide by .8333. 1152 is your answer. And this will get it quickly. Show More Responses Oops, I didn't tightly pack the basketballs, it would be closer to 1728 inflated basketballs if they were all tightly packed in a 10ftx10ftx10ft room. The correct answer is 1. You only said "basketball" in the question. The actual question is: "How many basketball[s] can you fit in this room” my take on this as follows: 1. Assume the size of the room 10' (ft)x 10' x 10' = 120" (inch) x 120" x 120" = 1728000 cu inch 2. size of the Basketball = 9" (inch) x 9" x 9" = 729 (basketball size ref @ http://www.nba.com/canada/Basketball_U_Game_Court-Canada_Generic_Article-18039.html) 3. 1728000 / 729 = 2370.370 ~ 2370 Basketballs (you cannot add 0.370 balls) Thanks Instead of working it out, anyone ever replied with something along the lines of: I'm sure you don't need to know how many basketballs can fit in here. Why don't we skip this question and save some time? I can put infinite number of basketballs, as long as I can keep enlarging the room. I don't need to do all the math or know the size of the basketball (which can be very small anyways - given the current technology I assume people can make a "basketball" in nano scale? Your are assuming the room is "empty"... What about you and the interviewer and the desk and the chairs and so forth. Those things take up space as well. Think about it. Because a basketball, like most matter in the universe, is comprised of 99.9999999% empty space (really, just a few atoms bound together by a "gluing" force we know little about, separated by empty space), if you manage to make a basketball dense enough, you could fit nearly an infinite number of them into any room. I wouldn't want to be around when that happens, because such things tend to create their own gravitational pulls, and event horizons. Between 1 and 1 million basketballs. You did not specify your error tolerance or accuracy requirement. It is always a mistake to jump to conclusions and provide answers without collecting data and doing the backup analysis. Google it. not too many if we want to adhere to fire code requirements. let's google the local FD and ask for guidance. Show More Responses An infinite number if the door is left open. I can fit more basketballs in this room than beach balls, but certainly less than footballs or baseballs. I guess that highest packing efficiency can be achieved if the spheres [or in this case 'basketballs'] are packed in a face centered system. So we can divide the whole room in the number of cubes with each cube's side = diameter of basket ball. Since one cube contains 4 balls so answer should be = 4 * No of cubes. Bingo! I guess Two. Two basketballs will fit in nicely in the room. Or five. Or 10. Or three. All are valid responses. The question doesn't ask what is the maximum number of basketballs that could fit in the room. Think back to high school chemistry. The most efficient packing schemes - hcp and fcc - where spheres nestle in the valley created by the spheres of an adjacent layer, fill almost 3/4 of the available volume - the actual figure is pi/(3*sqrt(2)), a smidgeon over 0.74. That only holds in regions of uninterrupted packing of course; a lack of fractional balls around the edges of the room will introduce complications we can only ignore if the length of the room's sides are all much larger than the ball diameter. So if the room volume is h*w*l and the volume of the ball is (4/3)*pi*r^3, and {h,w,l} >> r, and the packing coefficient is pi/(3*sqrt(2)), then the number of balls is: h*w*l * pi/(3*sqrt(2)) ----------------- (4/3)*pi*r^3 after cancelling stuff out this reduces to: h*w*l ----------------- 4*sqrt(2)*r^3 That's a bugger to do in your head, but if you're happy with an approximate packing density of 3/4 (close enough since the aforementioned edge effects will make the true value arbitrarily lower anyway), you can arrive at this simplified and much more memorable formula for the number of basketballs:: volume of room * sqrt(2) / volume of basketball-sized cube I can fit in just one basketball in the middle of the room and enjoy watching it! Or, I can maybe order one large basketball the size of the room, get it inside the room and inflate it till it fills the room...like MM said, it's a question of how many and not what's the max no of basketballs one can fit in that room With a gleam in my eye and a wry smile, I'd ask, "When is your next vacation?" I'd give out any random number lets say 100... If he say I counted and thats what is the answer (confidently). If he denies then ask him to prove you wrong by getting 100 basketballs :D say a big number based on the room if they ask how or y tell them to check it out....... I would ask myself how many basketballs I have first. Show More Responses I think the answer is ZERO.firstly if u use standard basketball then by calculation you can get the answer, but its an interview not an exam. n if u try to fit a basketball of the size of room then too some space will be left on the corners. so i think its ZERO |

### Linux Kernel Engineering at Google was asked...

You have 25 horses, what is the minimum number of races you can find the top 3. In one race you can race 5 horses, and you don't have a timer. 28 AnswersI don't know, but Google it, you'll find the answer. Once you know it, it's obvious. 12 Probably 8. First answer: at least 5 (you have to look at every horse). Second answer: 11. You can race five horses, replace 4th and 5th place horse by two horses from pool of horses that haven't raced, and continue doing this until all horses have raced. Since there are 25 horses, you need 1 race for the first five horses and 10 to go through the remaining 20. Third answer: 8. Round 1 (5 heats) : Race horses in heats of five. Eliminate all 4th and 5th place horses. (15 horses left) Round 2 (1 heat): Race winning horses from every heat. Eliminate 2nd and third place horses that lost to horses in round 2 that came third or worse. (7 horses left). Round 3 (1 heat): Pick any five horses. Race them. Eliminate bottom two and replace with remaining two horses. (5 horses left) Round 4 (1 heat): Eliminate bottom two. Note: after round 2 it may be possible to use some interesting decision tree mechanism to determine the three fastest horses using fewer horses per heat but you still need two heats to do that. This problem assumes horses don't get tired, no ties are possible and a horse's speed is deterministic race after race after race. Good assumptions for brain teasers, but not for real life. Show More Responses Actually, should be 7. Forgot that after round 2 you can eliminate one more horse leaving you with 6 horses, one of which (the winner of the second round), is the fastest horse of them all. One more race with the five horses not No.1 and you pick the top two. 6. First round consists of 5 races of 5 horses. Pull aside the winner of each race in the first round for the final heat and eliminate the bottom 2. 8. Run 5 races of 5 horses. (5) Put all the 3rd place horses in a race, winner is 3rd fastest. (6) Put all the 2nd place horses in a race, winner is 2nd fastest. (7) Put all the first place horses in a race, winner is fastest. (8) The third place horse was beaten by one of the 2nd place horses. So third stays in third. Same for the second place horse. chzwiz, r u sure u r not high? B, what happened in round 2? why 8 horses suddenly get eliminated by 1 race? again, do u know what you are smoking? oh, forget J,..... just speachless 7. chzwiz, your answer is incorrect. One of the first or second place horses could be 2nd fastest and/or 3rd fastest. I drew a grid to visualize the problem. First, run five races to establish 5 groups of internally ranked horses, and you can of course immediately eliminate 4 & 5 of each race. 1 2 3 x x 1 2 3 x x 1 2 3 x x 1 2 3 x x Then race 1st place horses, eliminate 4 & 5, and those they beat earlier. You can also eliminate the horses #3 beat, and the 3rd place horse from #2's first race. 1 ? ? X X 2 ? X X X 3 X X X X X X X X X X X X X X You know #1 is fastest. Race the remaining horses (2, 3 and ?'s), and the top two are 2nd and 3rd. After reading the above answers, this is the same as B's revised answer, but I found it easier to explain/visualize with the grid. @brad ... but isnt dat v dont have timer to know d ranking ... or my assumption is wrong?? I thought v know only 1 result of every race .. i.e. top 1 Spawn, it's true that you don't know timings, but you do know RANKINGS. I don't see errors in logic with each answer above. They may claim to discover the answer with fewer races, but they have too many assumptions or errors to be correct. To do this optimally and without any potential error, you must eliminate as many correctly placed horses as possible and eliminate the maximum number of non-win/place/show horses each round. Round 1: (Races 1-5) You must start with 5 heats @ 5 horses apiece. The non-Win/Place/Show horses of each round have been eliminated, leaving 15 horses. Round 2: (Race 6) You then race the top finishing horses against one another, leaving you with your overall fastest horse. We now have the Win horse, leaving only Place and Show as unknowns. This also eliminates the bottom two horses, leaving 2 horses from this race. There are also only two more unknown horses. Race 7) You may race the Place horses against one another. Only two survive this race, since we know that each of these horses can place 2nd at best. This leaves 2 horses from this race. (Race 8) You may also race the show horses of each round. Since they each have been beaten by two other horses in Round 1, only the 1st place horse of this round survives as the potentially 3rd best horse. This will leave 1 horse in this race to battle for the 2 remaining spots. Round 2 leaves 2 Horses (Race 6) + 2 Horses (Race 7) + 1 Horse (Race 8) = 5 Horses, for 2 unknown spots. Round 3: (Race 9) We can now have the final 5 horses race for the remaining two spots leaving us with the undisputed 2nd and 3rd places. Here is a more complex scenario below in which the top 2 horses come from the same original race and the later races are full of lame horses. Many of the solutions above do not address those problems. Each # is a horse, named by it's inherent ranking. X signifies 'eliminated horse' Race1 R2 R3 R4 R5 1-->R6 3-->R6 11-->R6 16-->R6 21-->R6 2-->R7 7-->R7 12-->R7 17-->R7 22-->R7 4-->R8 8-->R8 13-->R8 18-->R8 23-->R8 5X 9X 14X 19X 24X 6X 10X 15X 20X 25X Round 2: Race 6 (Winners) Race 7 (Places) Race 8 1 -->1st Place 2-->Race 9 4-->Race 9 3 -->Race 9 7-->Race 9 8X 11-->Race 9 12X 13X 16X 17X 18X 21X 22X 23X Round 3: Race 9 2P 3S 4X 7X 11X First Place = 1 Horse -- Race 6 Winner Second Place = 2 Horse -- Race 9 Winner Third Place = 3 Horse -- Race 9 2nd place To fix the formatting issues that appeared as spaces are eliminated above-- Race1________R2___________R3___________R4___________R5____ _1-->R6_______3-->R6_______11-->R6_______16-->R6_______21-->R6 _2-->R7_______7-->R7_______12-->R7_______17-->R7_______22-->R7 _4-->R8_______8-->R8_______13-->R8_______18-->R8_______23-->R8 _5X__________9X___________14X__________19X___________24X _6X__________10X__________15X__________20X___________25X Round 2: Race 6 (Winners)__________Race 7 (Places)__________ Race 8 1 -->1st Place_____________2-->Race 9______________4-->Race 9 3 -->Race 9_______________7-->Race 9 _____________ 8X 11-->Race 9______________12X____________________13X 16X_____________________17X____________________18X 21X_____________________22X____________________23X Round 3: Race 9 2P 3S 4X 7X 11X Less ascetically pleasing than the original, but it will suffice. Show More Responses This problem can be reduced to (viewed as) multiway mergesort: 1) split the horses into groups of five as if we had five files to sort 2) do a multiway mergesort but instead of sorting all horses, stop as soon as you get the top 3 We need one race per group to sort them (5 races total). And 3 more races to get the top 3. We will need 8 races. The interviewer might have been looking whether an applicant was able to spot this relation to algorithms or not. But if this was a brain teaser instead, maybe the answer is less than 8. The answer is definitely 7, here is a fantastic explanation: http://www.programmerinterview.com/index.php/puzzles/25-horses-3-fastest-5-races-puzzle/ Randomly race the horses 5 times and keep a winner's bracket. The 6th race will determine the fastest horse. This is trivial. The 2nd and 3rd fastest could be in the winner's bracket or they could be the 2nd or even 3rd fastest in one of the losing brackets. Then we have to race 2nd and 3rd place from the winners bracket as well as from each original bracket, which had 5. This means we have 12 horses to try. Randomly keep 2 horses out and race 5v5. Keep the top two horses from both. We have 6 horses now. Race 3v3 and keep the top two, leaving 4 horses. Then race these. I count 11? Brute force divide and conquer solution = 18 races. Just be aware of the brute force solution in case there's restriction where we can't use the memory to save the first 3 places. Those who want a system that averages that fastest solving time, the answer will be 7 races.. Those gamblers who want an algorithm that gives the fastest possible solving time (all though sometimes it WILL take longer) the answer is 6. Race 1-5: First 5 races of five.. We randomly seed with no overlaps.. we use this to eliminate the bottom two from each race. I am going to use a two digit number labeling system where the first digit is which race in heat one they competed in and the second digit is which place they obtained in that heat.. These are the horses we have left: 11 12 13 21 22 23 31 32 33 41 42 43 51 52 53 Race 6: We have the winners from each heat compete, and for ease of explanation lets say that they ranked 11, 21, 31, 41, 51.. Now we know that 41, 51 and all the horses slower than them (their heats) are out.. also, we know that any horse slower than 31 is out (ie. 32 & 33), and we know that any horse that is at least two horses slower than 21 is out (ie 23). This leaves 11, 12, 13, 21, 22, 31.. 6 horses. Possible rankings: 11 12 13 21 22 23 31 32 33 Race 7 Rank 1 is already known.. and we just need to know how to organize 12, 13, 21, 22, and 31.. And look at that!! that's 5 horses! We race those 5 and the top two receive the overall rank of 2nd and 3rd. 5 races in round one, 1 race in round 2, 1 race in round 3.. it took us 7 races.. Option two: 6 Races Now, an alternate answer.. when we read "What is the minimum number of races to find the top 3 horses" we can interpret that maybe they don't care about this method working every time.. instead they want to hit up the Vegas Casinos and test their luck, and maybe save some track time.. If i was a gambling man.. i would race the first group of those that i thought looked the strongest.. I would eliminate 2 in that race (we are now down to 23 horses).. and then race the 3rd fastest multiple times and hope that he gets first in the remaining races, thus eliminating 4 horses each time. This is going to be painful for the horse that placed 3rd in heat one. Race 1: Eliminate 2, 23 horses remaining Race 2.. Eliminate 4, 19 horses remaining Race 3.. 15 horses Race 4.. Eliminate 4, 11 horses Race 5.. Eliminate 4, 7 horses Race 6.. Eliminate 4, 3 horses.. The original top 3 from Race 1. So using method 2, we completed this race in 6 races instead of 7! I messed up the possible ranks after race 6.. That should have read.. 11 12 13 11 12 21 11 21 22 11 21 31 Please forgive me. Brad's explanation is the perfect one. All other explanations are junk and impossible to read and follow. Round1: (5 groups) remaining horse 15 Round: (1 groups). Topper from each heat Round: (1 gounds). Forget about the 4th and 5th Heat horses (becoz their toppers are at last place) go to the 3rd position 6 races as the 25 horses are divided into 5 groups each grouping 5 horses in each group , then the winner from each group would be 5 then there should be last n final race to find the first , second and third placed horse . in this way we can find our top 3 horses :) It should be 11. In each race you can only eliminate 4th and 5th place simply because there's a chance that the top 3 in that single heat are the 3 fastest of all the horses. So each race you can select 5 random horses each race or keep the top three in the following race, the outcome is the same. Show More Responses I get 8 races to guarantee you get the top three. 5 races of 5 to get the fastest horse from each group. 1 race to determine the fastest overall. The second fastest horse can be in the group (x) that produced the fastest, 1 race with the remaining 4 fastest from the other groups and the second fastest from group x. That race will produce the second fastest overall guaranteed. 1 more race with the 3 or 4 from the original winners and the replacement from the group that produced the second place horse. That makes 8 races. I dont get it.. It shoudl be five races right? U will know how long each horse takes to cover same distance. Pick the three that took shortest. Y need more rounds? If u down vote my answer, u have the obligation to explain why 😜 Answer is 6. You will have 5 races and 5 winners. Next race with 5 winners is the 6th race and you get top 3. You're welcome. It would be 7, mainly because since there only 5 racers each round, then it would be tournament style. As you can tell, tournament style never determines the rankings in the short term. (Imagine if a new tennis player played against Roger Federer and he loses. He's not bad, he's just really unlucky haha) So in order to determine the answer, you would have to use massive logic and reasoning. First step is obvious: you get 5 sets of horses to race through 5 races. So the number is already at 5. We get the top horse in each one and note them. However, one problem is that you have to consider if fastest horses could lie all in the first, second, third, fourth, or fifth group. But we can't determine that yet, so let's race one more time with the winners of each race. Second step: Race with each winner from their groups. That makes 6 total races so far. Ok, now we can get somewhere with this. So now, its a question of which horses we can eliminate to determine the next race. Who can we eliminate though? Well, we can get rid of: - All the horses in the group with the last race that were 4th and 5th place. This makes sense since if the winner of their groups only made 4th and 5th place in the tournament style race, then they are definitely not the fastest horses. 15 horses remaining. - Well, we can also get rid of the last two horses of each group since we are only looking for the top 3. 9 horses remaining. - We also can get rid of the first place winner since we already know he is definitely the best. 8 horses remaining. - Since we already determined who the fastest horse is, now we have to determine who the second and third fastest horse can be. In that case, the second place horse from the last round can get rid of the third horse of that group, since he definitely has no shot of being the first or second fastest horse of this new race. Also, in the third group, we can get rid of the second and third horse in the group due to the same reasoning above. 5 horses remaining. Oh wow! We now have 5 horses left! This means we can just have a clean race and find the second and third fastest horse. So overall, the answer is 7 races! 7 |

### Data Scientist at Facebook was asked...

You're about to get on a plane to Seattle. You want to know if you should bring an umbrella. You call 3 random friends of yours who live there and ask each independently if it's raining. Each of your friends has a 2/3 chance of telling you the truth and a 1/3 chance of messing with you by lying. All 3 friends tell you that "Yes" it is raining. What is the probability that it's actually raining in Seattle? 30 AnswersBayesian stats: you should estimate the prior probability that it's raining on any given day in Seattle. If you mention this or ask the interviewer will tell you to use 25%. Then it's straight-forward: P(raining | Yes,Yes,Yes) = Prior(raining) * P(Yes,Yes,Yes | raining) / P(Yes, Yes, Yes) P(Yes,Yes,Yes) = P(raining) * P(Yes,Yes,Yes | raining) + P(not-raining) * P(Yes,Yes,Yes | not-raining) = 0.25*(2/3)^3 + 0.75*(1/3)^3 = 0.25*(8/27) + 0.75*(1/27) P(raining | Yes,Yes,Yes) = 0.25*(8/27) / ( 0.25*8/27 + 0.75*1/27 ) **Bonus points if you notice that you don't need a calculator since all the 27's cancel out and you can multiply top and bottom by 4. P(training | Yes,Yes,Yes) = 8 / ( 8 + 3 ) = 8/11 But honestly, you're going to Seattle, so the answer should always be: "YES, I'm bringing an umbrella!" (yeah yeah, unless your friends mess with you ALL the time ;) I thought about this a little differently from a non-bayes perspective. It's raining if any ONE of the friends is telling the truth, because if they are telling the truth then it is raining. If all of them are lieing, then it isn't raining because they told you that it was raining. So what you want is the probability that any one person is telling the truth. Which is simply 1-Pr(all lie) = 26/27 Anyone let me know if I'm wrong here! Here's another perspective on how to answer a question like this: Bring an umbrella. It's Seattle - if it's not raining right now, it probably will be by the time you get there. Show More Responses I flagged Nub data scientist's answer as useful, because it shows an interesting flaw in reasoning. The 3 random variables are not to be treated as intrinsically independent. Only conditioned on the truth (raining/not raining) are they independent. Isn't the answer 2/3. The key thing is that they are ALL saying "Yes". You can't have all 3 says yes and have some people lying and some people telling the truth. It either is raining or it isn't. Not both. They either are all lying or all telling the truth. Since they are all in agreement (all lying or all truthful), they are essentially voting as one person. What is the probability that one person is telling the truth? 2/3 Answer from a frequentist perspective: Suppose there was one person. P(YES|raining) is twice (2/3 / 1/3) as likely as P(LIE|notraining), so the P(raining) is 2/3. If instead n people all say YES, then they are either all telling the truth, or all lying. The outcome that they are all telling the truth is (2/3)^n / (1/3)^n = 2^n as likely as the outcome that they are not. Thus P(ALL YES | raining) = 2^n / (2^n + 1) = 8/9 for n=3 Notice that this corresponds exactly the bayesian answer when prior(raining) = 1/2. I'm not sure why it's not just as simple as this: All three friends say it is raining. Each friend has prob. 1/3 of lying. Since the friends all say the same thing, they are either all telling the truth or all lying. The question asks what is the probability that it is raining. This is equivalent to asking, what is the probability that all three friends are telling the truth. And that is equivalent to asking, what is the probability that not one of them is lying. Since the the friends were asked independently, this should equal 1 - (1/3 * 1/3 * 1/3) = 0.962. Ah. Looks like my answer agrees with "nub data scientist". What is the probability that both he and I are wrong? :-) TLP and nub data scientists, Your answers include possibilities which are not feasible; we cannot have any combination of 2/3 and 1/3 together... what about (2/3)^3? I agree with TLP and nub scientist. For me, the question is really (1 - the odds that all three of your friends are lying to you) Clearly 1 - 1/3 * 1/3 * 1/3. It's convenient that they all gave the same answer, otherwise it would be more difficult. Let Y denote rain, N denote no rain Actual Answer probability ------------------------------------------ Y=> 8/27 YYY, 1/27 NNN, 12/27 YYN, 6/27 YNN N=> 1/27 YYY, 8/27 NNN, 6/27 YYN, 12/27 YNN So, P(Y|YYY) = (8/8+1) = 8/9 The probability of raining is that they are all telling the truth, therefore, (2/3)^3. P(rain / yes yes yes) = (2/3)^3 / ((2/3)^3 + (1/3)^3) =(8/27) / ((8/27) + (1/27)) = 8 / (8 +1) = 8/9 26/27 is incorrect. That is the number of times that at least one friend would tell you the truth (i.e., 1 - probability that would all lie: 1/27). What you have to figure out is the odds it raining | (i.e., given) all 3 friends told you the same thing. Because they all say the same thing, they must all either be lying or they must all be telling the truth. What are the odds that would all lie and all tell the truth? In 1/27 times, they would the all lie and and in 8/27 times they would all tell the truth. So there are 9 ways in which all your friends would tell you the same thing. And in 8 of them (8 out of 9) they would be telling you the truth. Show More Responses There is an obvious conceptual reason as to why several answers here (ones that don't use Bayes' formula) are incorrect. The probability in question has to depend on the probability of rain in Seattle. If, for the sake of discussion, it ALWAYS rains in Seattle, i.e. P(rain)=1, then the required prob. is always 1 as well. Likewise if it's a place where it never rains, or if the question asks about the prob. of it raining elephants given the 3 friends said yes, it'd be still 0. I believe this is a std. textbook example of the Bayes' formula, anything short of that I don't think will work out. Please correct me if incorrect. But I would just prefer to condition. either they are all telling the truth and its it raining or they are all lying and it is not raining. P(rain)=P(rain|truth,truth,truth)*P(truth,truth, truth)+P(rain|lie,lie,lie)*P(lie,lie,lie) notice that truth does not mean yes it is raining, it simply corresponds to them telling the truth. Since they said yes, IF they were lying and we knew they were lying then the probability of rain would be zero, thus eliminating the second term. P(rain)=P(rain|3xtruth)*P(3xtruth) and the probability of the truth is (2/3)^3 and the probability of rain if they are telling the truth is 1. I did a little skipping of steps, since truth doesnt equal yes, but i just sort of meshed it toegher towards the end YES=yes,yes,yes T=truth, truth, truth L=lie,lie,lie P(Rain|YES)=P(Rain|YES,T)*P(T)+P(Rain|YES,L)*P(L) P(Rain|YES,L)=0==> whats the probability of rain given we know that they are lying and theyve told us it is raining. P(Rain|YES)=P(Rain|YES,T)*P(T) P(Rain|YES,T)=1==> whats the probability of it raining given that they are telling the truth and have told us its raining then P(T)=(2/3)^3 its obvious. why in the world would i do bayesian methods when its certain I think the first answer is incorrect. The basic flaw is that it is assumed that all three friends lie together or be honest together, so it does not take the cases of Yes.no.Yes or Yes.Yes.no ...etc For the correct answer we need to update posterior probability after each yes so Assuming P(raining) =0.75 prior probabilty P(raining | yes) = (2/3)*0.75 / ( (2/3)*0.75 + (1/3)*0.25 ) = 6/7 P(raining | yes,yes) = (6/7)*(2/3) / ( 6/7*2/3 + 1/7*1/3) = 12/13 P(raining | yes,yes,yes) = (12/13)*(2/3) / ( 12/13*2/3 + 1/13*1/3) = 24/25 I dont see the interview saying that all friends are sitting together so they are independent which means they can lie separately I agree with (2/3)^3. Interview Candidate solves this problem using Bayesian stats despite the fact that no enough information is given to do Bayesian probability analysis i.e. he had to pull the probability of it raining in Seattle out of thin air when it was not given in the interview question. With only the information from the interview question, we have to assume that friends are either all lying or all telling the truth. Let truth=T and lie=L P(TTT)=8/27, P(LLL)=1/27, P(TLL)=2/27,P(TTL)=4/27. But we know that they all had the same answer, so we must compare P(TTT) to P(LLL). P(TTT) is 8 times more likely than P(LLL), so we have P(All same answers|TTT)=8/9, P(All same answers|LLL)=1/9. Therefore the solution given ONLY THE INFORMATION GIVEN is P(Rain)=8/9, P(Dry)=1/9. This problem requires the marginal probability of rain to solve, following Interview Candidate's answer. M.B. provides the rationale behind why the bayes approach is necessary: if the pr(rain) = 0, then the pr(rain|y, y, y) = 0. (maybe it is July in Seattle). A few conceptual problems in many answers that I want to point out: 1) There is lots of conflation between Pr(truth) and Pr(Y). Pr(truth) = Pr(Y|R) does not equal Pr(Y). 2) Consider there is only a single friend and they say yes, the logical conclusion from a lot of these answers is that Pr(Rain|Yes) = Pr(Yes|Rain) = 2/3, which is not correct. Bayes' rule is very clear in this simpler case. 3) The friends' answers are conditionally independent assuming no collusion. The combinations of their honesty/lying adds no additional information. The marginal probabilities are not independent, Pr(y,y,y) does not equal pr(y)^3, it equals pr(y,y,y,rain) + pr(y,y,y, no rain), the integration of the joint space over rain. Using conditional independence and bayes rule, this becomes: pr(y|rain)^3*pr(rain) + pr(y|no rain)^3(1-pr(rain)). A more general solution using Pr(rain) = r. Pr(rain|y,y,y) = Pr(y,y,y|rain)*pr(rain)/pr(y,y,y) #Bayes' formula pr(y,y,y|rain) = pr(y|rain)^3 = (2/3)^3 #conditional independence pr(y,y,y) = pr(y|rain)^3*pr(rain) + pr(y|no rain)^3*pr(no rain) #by definition, see point 3 the answer: r*(2/3)^3 / [r*(2/3)^3 + (1 - r)*(1/3)^3] It should be (2/3)^3, I think zen and todo is correct. As a big dumb animal, I have to write out a probability tree and thing about this simply. You only have 2 scenarios where all three say it is raining (all three are telling the truth-raining OR all three are lying - not raining). Assume the probability of rain is 0.5 for simplicity. P(Rain and YYY) = 1/2 * 2/3 * 2/3 * 2/3 = 8/54 P(Not Rain and YYY) = 1/2 * 1/3 * 1/3 * 1/3 = 1/54 Thus P(Rain | YYY) = P(Rain and YYY) / [P(Rain and YYY) + P(Not Rain and YYY)] = 8 / (8+1) = 8/9 I know it isn't the most mathematically rigorous or syntactically correct solution, but I'd bet a pretty penny that the answer is 8/9 with the following assumptions (P(rain) = 0.5 and naive bayes - friends didn't collaborate). Most of the answers/comments made all unconditional assumptions except a few reasonings that lead to the 8/9 probability. Note that the question states that "Each of your friends has a 2/3 chance of telling you the truth". This essentially means P(raining, yes) + P (non-raining, no) = 2/3. Any attempts to interpret this as conditional probability P(raining | yes) = 2/3 or P(yes | raining) = 2/3 are making other assumptions. Show More Responses 8/27 is not the answer. For the weather to be nice in this case, all 3 of your friend NEED to have lied to you. Therefor the odds are 1/27. It's really shocking to see how many people post incorrect answers here with such confidence. That said, Bayes' rule is somewhat counterintuitive if you're not familiar with probability theory. Let P(y|r) = prob of each yes given raining = 2/3, P(y|n) = prob yes given not raining = 1/3. Let P(r) = probability of rain = 1/4 given the prior knowledge. P(n) = probability of no rain = 3/4. P(r | y^3) = ( P(y^3 | r) P(r) ) / ( P(y^3 | r) P(r) + P(y^3 | n) P(n) ) = ( P(y | r)^3 P(r) ) / ( P(y | r)^3 P(r) + P(y | n)^3 P(n) ) = ( (2/3)^3 (1/4) / ( (2/3)^3 (1/4) + (1/3)^3 (3/4) ) = (2/27) / ( (2/27) + (.75/27) ) = 2/2.75 = 8/11 What if the answer is 50% since the chance of rain and not rain does not depend on what your friends tell you. In the absence of further information, the only correct answer is the posterior probability of rain p is in the interval (0, 1). In the absence of further information any prior is as good as any other, so by implication the posterior can take any value as well. The interval for p can be restricted to [0, 1] on the assumption that the question to the friends would not be posed if the prior is absolute certainty whether it will rain or not. With the further assumption that the prior probability is measured with limited precision (e.g. rounded to a percentage point), the posterior would be in the interval (0,075, 1). If the alternative assumption is made that information from the friends will be requested only if it had any chance to move the posterior below or above 0.5, the posterior interval for the probability is (0.5, 1). any more precise answer than that requires further information about the prior which is not supplied in the original problem formulation. Also note that even a precise answer about the probability of rain is not sufficient to answer the question whether an umbrella should be brought or not. Assume probability of raining in Seattle P(R) = 1/4 Assume friend says Y 50% of the time (Theoretical probability) P(Y) = 1/2 Probability of friend saying yes given its raining P(Y/R) = 2/3 Probability of 3 friends saying yes given its raining = P(YYY/R) = 8/27 Probability of 3 friends saying yes = P(YYY) = 1/8 P(R/YYY) * P(YYY) = P(YYY/R)*P(R) P(R/YYY) = 8/27*1/4/(1/8) = 16/27 (About 59%) A posterior probability of 59% given 3 yes and a prior probability of 25% sounds reasonable to me The probability of each of the friend say "YES" is 2/3 * 2/3 * 2/3 = 8/27. Now the probability that it is actually raining in Seattle depends on that how do I select them to phone. There is only three way to select and phone them. So, the probability that it is actually raining in Seattle is 3 * (8/27) = 8/9. Probability that it is raining given that all 3 of them said "yes" = P(AT LEAST one of them is telling the truth) = P(exactly 1 of them telling the truth) + P(2 of them telling the truth) + P(all 3 of them telling the truth) P(exactly 1 of them telling the truth) = P(of first person telling truth) * P(of 2nd person telling lie) * P(of 3rd person telling a lie) = (2/3) * (1/3) * (1/3) = 2/27 + P(exactly 2 of them telling the truth) = P(of first person telling truth) * P(of 2nd person telling the truth) * P(of 3rd person telling a lie) = (2/3) * (2/3) * (1/3) = 4/27 + P(exactly 3 of them telling the truth) = P(of first person telling truth) * P(of 2nd person telling the truth) * P(of 3rd person telling the truth) = (2/3) * (2/3) * (2/3) = 8/27 ANSWER: Probability that it is raining given that all 3 of them said "yes" = P(AT LEAST one of them is telling the truth) = P(exactly 1 of them telling the truth) + P(2 of them telling the truth) + P(all 3 of them telling the truth) = (2/27) + (4/27) + (8/27) = 14/27 |

### Software Engineer at Google was asked...

Given the list of points of the skyline of a city in order (from East to West) Find the maximal rectangle contained in this skyline. I was asked to write the code. I managed to find the algorithm but was not sufficient. 21 Answersjust google for skyline. @Interview Candidate Have you found any particularly clear explanations? I'm working on a solution - I'll post it later tonight - but it'd be nice to confirm my understanding. Thanks. Clear? Well, to be more exact: Given N points on 2-plane: (x1, y1), (x2,y2), ... , (xN, yN) s.t. x1=0, xN= 0 and for all 10,yM > 0. Find the maximum value of the area of a rectangle inside the region bounded by these points and the x-axis. You can assume that the rectangle's edges are going to be parallel to the x,y axes. Show More Responses Here's an O(n^3) dynamic programming solution. It's pretty ugly, but it seems to work. More elegant/efficient solutions would be greatly appreciated. -------------------------------------------- import java.util.ArrayList; public class Skyline { private int maxX; private int maxY; public String[] findLargestRectangle(String[] points){ // First translate the points into a boolean matrix. // The cell [i][j] in the matrix should be true if // it appears under the skyline and false otherwise. boolean[][] cells = this.pointsToMatrix(points); System.out.println("Matrix is: "); this.printBooleanMatrix(cells,maxX,maxY); // Now we calculate rectangle size. Define // s[i][j] to be the size of the rectangle // with (i,j) at its upper left corner. int[][] s = new int[maxX+1][maxY+1]; int maxSizeX = 0; int maxSizeY = 0; int maxSize = 0; for (int i = 0; i maxSize){ maxSize = max; maxSizeX = i; maxSizeY = j; } } } System.out.println("Size matrix is: "); this.printIntegerMatrix(s,maxX,maxY); System.out.println("Maximum rectangle has size " + maxSize + "."); System.out.println("Its upper left corner is (" + maxSizeX + "," + maxSizeY + ")."); return null; } // Points to be given as "1 0", "2 5", etc. private boolean[][] pointsToMatrix(String[] points){ ArrayList list = new ArrayList(); // The maximum x-value will be that of the last point. maxX = Integer.parseInt(points[points.length-1].split(" ")[0]); maxY = 0; for (int i = 0; i maxY) maxY = y; list.add(new Point(x,y)); // Assume there are no duplicates } System.out.println("Points are: " + list); System.out.println(" maxX = " + maxX + ", maxY = " + maxY); boolean[][] m = new boolean[maxX+1][maxY+1]; int prevX = 0; int prevY = -1; for (int k = 0; k 0){ m[x][j] = true; j--; } } else { // Look left. If the cell to the left is false, then this cell // is true (start of rectangle top). The value of the cells below // is also true. // // If the cell to the left is true and the previous point had the same value // of x, then this cell represents the start of another rectangle. Set its value // to true and the values of the cells below to true. if ((! m[x-1][y]) || (prevX == x)){ m[x][y] = true; while (j > 0){ m[x][j] = true; j--; } // If the previous value of y is the same as this value of y and the // difference between x values is greater than 1, fill in the cells // in between. if (prevY == y && (x - prevX > 1)){ int i = x-1; while (i > prevX){ j = y; while (j > 0){ m[i][j] = true; j--; } i--; } } } // If the cell to the left is true and the previous point had a different // value of x, then this cell is false (end of rectangle top). Set it and // the cells below it to false. This cell may be inside another rectangle, // in which case its value will be reset to true. else { m[x][y] = false; while (j > 0){ m[x][j] = false; j--; } } } prevX = x; prevY = y; //System.out.println("After " + p + ", matrix is: "); //this.printBooleanMatrix(m,maxX,maxY); } return m; } (cont'd) private void printIntegerMatrix(int[][] b, int maxX, int maxY){ for (int j = maxY; j >=0; j--){ for (int i = 0; i =0; j--){ for (int i = 0; i <= maxX; i++){ System.out.print(String.format("%8b",b[i][j])); } System.out.println(); } } class Point implements Comparable{ int x; int y; Point(int x, int y){ this.x = x; this.y = y; } public int compareTo(Object o){ Point p = (Point) o; return (this.x != p.x ? this.x - p.x : this.y - p.y); } public boolean equals(Object o){ if (! (o instanceof Point)) return false; Point p = (Point) o; return (this.x == p.x && this.y == p.y); } public int hashCode(){ return x*37 + y*19 + x*11 + y*7; } public String toString(){ return "(" + x + "," + y + ")"; } } /** * @param args */ public static void main(String[] args) { String[] points = {"0 2","1 2","1 1","2 1","2 3","3 3","3 0"}; Skyline s = new Skyline(); s.findLargestRectangle(points); System.out.println(); String[] points1 = {"0 1","1 1","1 4","2 4","2 3","3 3","3 6","4 6","5 3","7 3","7 7","8 7"}; s = new Skyline(); s.findLargestRectangle(points1); } } Output: Points are: [(0,2), (1,2), (1,1), (2,1), (2,3), (3,3), (3,0)] maxX = 3, maxY = 3 Matrix is: false false true false true false true false true true true false false false false false Size matrix is: 0 0 3 0 2 0 2 0 3 2 1 0 0 0 0 0 Maximum rectangle has size 3. Its upper left corner is (0,1). Points are: [(0,1), (1,1), (1,4), (2,4), (2,3), (3,3), (3,6), (4,6), (5,3), (7,3), (7,7), (8,7)] maxX = 8, maxY = 7 Matrix is: false false false false false false false true false false false false true false false false true false false false false true false false false true false false true false true false false false true false false true true true false true true true false false true true true false true true true false true true true true false true true true false false false false false false false false false false Size matrix is: 0 0 0 0 0 0 0 7 0 0 0 0 6 0 0 0 6 0 0 0 0 5 0 0 0 5 0 0 4 0 4 0 0 0 4 0 0 9 6 3 0 9 6 3 0 0 6 4 2 0 6 4 2 0 4 3 2 1 0 3 2 1 0 0 0 0 0 0 0 0 0 0 Maximum rectangle has size 9. Its upper left corner is (1,3). Found bug: public *int* findLargestRectangle(String[] points){ ... *return maxSize*; } (obviously) I don't mean to discourage you but there is no way that you can get away with an answer that works in O(N^3) for this question and even if the interviewer was happy with this performance, it would be impossible for you to write this kind of code given a reasonable time limit for the interview (which is around 45 minutes, and that's the entire interview which includes introduction and possibly some other easy questions) You can solve this in O(N). I don't have time to write a solution right now, I strongly recommend looking at Topcoder's skyline problems and contestants' solutions for an insight. best of luck to you For others' reference: http://www.topcoder.com/stat?c=problem_statement&pm=7473&rd=10661 http://www.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm337 https://www.spoj.pl/problems/HISTOGRA/ http://www.informatik.uni-ulm.de/acm/Locals/2003/html/judge.html Here's a much nicer O(n^2) solution. As Anonymous said, there's an O(n) solution, too. /* * In this input array a, the ith building * has height a[i], which means its lower left * corner is at (i,0) and its upper right corner * is at (i+1,a[i]). All buildings have width 1. * The total width of the skyline is n. */ public long getMax(long[] a){ int n = a.length; int[] leftWidths = new int[n]; int[] rightWidths = new int[n]; // For each building, check how many units width to the left of the // top block of this building we can move before we are no longer // in a building. for (int i = 0; i = 0) && a[x] >= a[i]) { x--; count++; } leftWidths[i] = count; } // For each building, check how many units width to the right of the // top block of this building we can move before we are no longer // in a building. for (int i = 0; i = a[i]) { x++; count++; } rightWidths[i] = count; } // Now find the maximum rectangle. The value of the ith building's // rectangle is its horizontal width times its height, or // (1 + leftWidths[i] + rightWidths[i]) * a[i]. long maxArea = 1; for (int i = 0; i maxArea) { maxArea = nextArea; } } return maxArea; } O(n) solution: /* * Basic idea: use a stack to store the buildings. Look at * the buildings in left-to-right order (west to east). If a * building is taller than the building on the top of the stack * (the tallest building to its left), push it onto * the stack. If a building is equal in height to the building on the * top, skip it. If a building is shorter than the building on the top, * it is not part of the maximum rectangle that is topped by the tallest * building to its left. Pop that tallest building, calculate its area and * compare it to the current main area, then repeat the comparison * procedure with the new tallest building. * * Along the way, track the number of buildings to the left and right of a * given building that would participate in that building's maximum * rectangle. The number to the left is equal to the number of buildings * that are popped off the stack before this building is pushed - that is * the number of buildings to the left of this building that are taller. * We do not need to worry about the buildings that are equal in height * since they are discarded (they are accounted for in the topBuilding's * rightWidth count). * * The number of buildings to the right of this building that participate * in this building's maximum rectangle is equal to the number of buildings * that are discarded because they are equal to this building's height * plus the number of buildings that are pushed onto the stack because they * are taller than this building while this building is on the top of the * stack. * * In this input array a, the ith building has height a[i], which means * its lower left corner is at (i,0) and its upper right corner is at * (i+1,a[i]). All buildings have width 1. The total width of the skyline * is n. */ public long getMax_useStack(long[] a){ Stack stack = new Stack(); int n = a.length; long maxArea = 1; // Process the buildings in left-to-right order. for (int i= 0; i < n; i++){ Building nextBuilding = new Building(a[i]); // Keep track of the number of buildings that we pop before we // push nextBuilding. That number will be equal to the number // of buildings to the immediate left of nextBuilding that are // taller in size. int popCount = 0; // If the stack is empty, push the next building onto the stack. // There are no buildings to its left, so we do not need to // update nextBuilding.leftWidth. if (stack.empty()) { stack.push(nextBuilding); continue; } (cont'd) // Otherwise, compare the new building's height to the building on // the top of the stack until the new building is either // discarded (if it is equal in size) or pushed (if it is taller). while (! stack.empty()){ Building topBuilding = stack.peek(); long heightDiff= nextBuilding.height - topBuilding.height; // If the new building is equal in height, skip it. Increment // the rightWidths count of topBuilding as its largest // rectangle goes through the new building. if (heightDiff == 0) { topBuilding.rightWidth++; break; } // If the new building is greater in height, push it onto the // stack. The number of buildings to the immediate left of it // that are taller is equal to the number of buildings that // were popped before this point, its popCount. Set its // leftWidth equal to its popCount. Increment the rightWidths // count of the top building as its largest rectangle goes // through the new building. if (heightDiff > 0) { nextBuilding.leftWidth = popCount; topBuilding.rightWidth++; stack.push(nextBuilding); break; } // If the new building is less in height, update the maximum area // with regards to the element at the top of the stack. long topArea = topBuilding.getArea(); if (topArea > maxArea){ maxArea = topArea; } // Then discard the top element and repeat the comparison // procedure with the current next building. stack.pop(); popCount++; } } // If all buildings have been processed and the stack is not yet empty, // finish the remaining subproblems by updating the maximum area // with regards to the building at the top of the stack. while (! stack.empty()){ Building topBuilding = stack.pop(); long topArea = topBuilding.getArea(); if (topArea > maxArea){ maxArea = topArea; } } return maxArea; } class Building { long height; int leftWidth; int rightWidth; Building(long y){ this.height = y; leftWidth = 0; rightWidth = 0; } long getArea(){ return height * (1 + leftWidth + rightWidth); } } ellemeno, Nice solution/explanation. However, maxArea should be initialized to 0. @logimech Right. :) Thanks. Show More Responses ellemeno: The program has bug. We need to store the building's x cordinate. And when the nextbuilding is shorter than the top one, we need to update each popped building's rightwidth as topbuilding.x - nextbuilding.x Isnt this the convex hull problem? The O(n) algorithm does not work. I have another solution for it, however. Suppose we have the array of heights a of length n. We are looking for the smallest building index (let's say x and divide the problem in 2: the left part ( between 0 and i - 1) and the right part (between i + 1 and n - 1). Then we compute the area that can be build using the building indexed with i: a[i] * (n - 1 - 0 + 1) = n * a[i]. We compare this area with the ones obtained from the left and from the right part and return the result. Therefore, the complexity will be: N * time to find the index of the smallest building in a range - which is RMQ problem that can be solved in O(logn) and O(n) preporcessing time (and O(N) space). Therefore, the complexity is O( N log N). It works for 3 6 5 6 2 4: the solution is 3 * 5 = 15. The problem is known as the biggest rectangle below a histogram. An old question with my answer. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SkylineTest { class Program { static void Main(string[] args) { Point[] pointList = new Point[10]{new Point(0, 1) ,new Point(1,1) ,new Point(1,2) ,new Point(2,1) ,new Point(2,2) ,new Point(2,0) ,new Point(4,0) ,new Point(4,6) ,new Point(5,6) ,new Point(5,0)}; Skyline sl = new Skyline(pointList); Point maxPoint = sl.CalculateMaxRanctangle(); Console.WriteLine("MaxPoint:" + maxPoint.X + " " + maxPoint.Y); Console.WriteLine("MaxArea:" + sl.MaxArea); Console.ReadLine(); } } public struct Point { private int _x; private int _y; public int X { get { return _x; } } public int Y { get { return _y; } } public Point(int x, int y) { _x = x; _y = y; } } public class Skyline { private Point[] _pointList; private int _maxArea=0; private Point MaxRactanglePoint; public int MaxArea { get { return _maxArea; } } public Skyline(Point[] pointList) { _pointList = pointList; } public Point CalculateMaxRanctangle() { Point maxPoint = new Point(0, 0); for (int index = 0; index 2) { for (int i = index - 2; i >= 0; i -= 2) { if (_pointList[i].Y >= _pointList[index].Y) areaForPoint += (_pointList[i+2].X - _pointList[i].X) * _pointList[index].Y; else break; } } if(index= _pointList[index].Y) areaForPoint += (_pointList[i].X - _pointList[i-2].X) * _pointList[index].Y; else break; } if (areaForPoint > _maxArea) { _maxArea = areaForPoint; maxPoint = _pointList[index]; } index += 2; } } return maxPoint; } } } i dont know if i understand the assignement correctly, but shouldnt ne sufficient to iterate all coorfinates and find min x, min y, max x, max and then calculate the area given by this rectangle? Hi Guys, there is O(N) solution using STACK. http://www.geeksforgeeks.org/largest-rectangle-under-histogram/ Psuedocode //Iterate through points one time where a point further east is greater than a point farther west, a point higher up is greater than a point lower down. //if x greatestX, greatestX = x //if y greatestY, greatestY = y //Equate (greatestX - smallestX) by (greatestY - smallestY) For some reason that left out like half of my psuedocode |

### QA Automation Engineer at BitTorrent was asked...

A dwarf-killing giant lines up 10 dwarfs from shortest to tallest. Each dwarf can see all the shortest dwarfs in front of him, but cannot see the dwarfs behind himself. The giant randomly puts a white or black hat on each dwarf. No dwarf can see their own hat. The giant tells all the dwarfs that he will ask each dwarf, starting with the tallest, for the color of his hat. If the dwarf answers incorrectly, the giant will kill the dwarf. Each dwarf can hear the previous answers, but cannot hear when a dwarf is killed. What strategy should be used to kill the fewest dwarfs, and what is the minimum number of dwarfs that can be saved with this strategy? 21 AnswersThere are 2 different strategies, each dependent on whether there are an even or odd number of white and black hats in play. The minimum number of dwarfs that can be saved with the correct strategy is 9. There is only one strategy, does not matter how many white or black hats they are. They are always 9 dwarfs that could be saved. You just have to know about XOR. Well... In my opinion all can be saved! The tallest dwarf can see 9 hats in front of him ( 4 white and 5 black hats or the other way around). Then he knows the color of his hat because there has to be 5black and 5 white hats. The next dwarf by the size just has to believe to the tallest dwarf that he is right-(and he is) In addition ,he can see 8 hats in front of him and when he adds the color of the tallest dwarf he knows which color he has. Again,the 3rd one in a row knows about 2 colors before and can see 7 colors in front of him.And when he adds 2 colors he already had heard of -he knows total number of 9 hats as well.So he just has to see which color is less presented and that is the color of his hat. And so on until the last dwarf...All saved Show More Responses the question does not mention that there will be equal number of white and black hats ! Since they do not know, how many black or white hats there are, the following strategy will save min 5 dwarfs: The first dwarf asked names the color of the hat of the 2. dwarf. He has a 50% chance that that's correct. Anyway, the second dwarf then knows, the color of his hat and names it correctly. the 3. dwarf again names the color of the hat of the 4th dwarf and has a 50% chance to survive, while the 4th dwarf can name the correct color of his hat. a.s.o. => all dwarfs with an even number will survive and all the others have a 50% chance Don't over-think it. Each dwarf simply has to state the color of the hat worn by the dwarf directly in front of him. The tallest would have to sacrifice himself in order to save the other 9. Easy. The tallest is the only one that cannot be saved so instead of trying to guess his color, he yells out a sequence of letters starting from the shortest like BWBBBWWBB. Next :) Your going to definitly get 9 because when the dwarves collude the tallest tells the next tallest his hat color and so on down the line. Now you have a 50/50 chance that the tallest will get his color correct and live so you have 9 with a 50% chance of 10 Each dwarf can state the color of the hat worn by the dwarf in front of him, but the thing is, that color may not be the color of his own hat.So he may be killed by the giant.In that case, as mentioned above all odds should tell the color of next so that all even number will be alive and they have 50% chance of surviving. Think broadband communication. Exploit the capabilities of the communications medium. A minimum of nine dwarves can be saved based on the information provided in the original post I viewed. The strategy is for each dwarf to employ the expected language to communicate the color of their own hat to the giant, while simultaneously employing a vocal pitch protocol to indicate the color of the hat of the dwarf in front of him, high pitch for white and low pitch for black. The original post, indicates the dwarves may collude prior to the distribution of hats, so there is opportunity to negotiate such a simple broadband communication protocol. The tallest dwarf only has a 50/50 chance since the number of black and white hats in play is not known (rhetorical question, what are the odds the tallest dwarf's hat is black if he turns to find that all nine hats in front of him are white? I don't know, but odds are high that the giant is a sadistic bloke). The original post I viewed is here. http://www.businessinsider.com/toughest-job-interview-questions-2013-7#a-dwarf-killing-giant-lines-up-10-dwarfs-from-shortest-to-tallest-each-dwarf-can-see-all-the-shortest-dwarfs-in-front-of-him-but-cannot-see-the-dwarfs-behind-himself-the-giant-randomly-puts-a-white-or-black-hat-on-each-dwarf-no-dwarf-can-see-their-own-hat-the-giant-tells-all-the-dwarfs-that-he-will-ask-each-dwarf-starting-with-the-tallest-for-the-color-of-his-hat-if-the-dwarf-answers-incorrectly-the-giant-will-kill-the-dwarf-each-dwarf-can-hear-the-previous-answers-but-cannot-hear-when-a-dwarf-is-killed-the-dwarves-are-given-an-opportunity-to-collude-before-the-hats-are-distributed-what-strategy-should-be-used-to-kill-the-fewest-dwarfs-and-what-is-the-minimum-number-of-dwarfs-that-can-be-saved-with-this-strategy-11 So reading the answers provided they all have some assumptions e.g. that there are as much white hats as there are black hats. I think that Christian's comment on aug 13-2013 was very close but I'm thinking about communication integrity confirmation techniques. One of them is using a parity bit to confirm the message was correct. This could be applied right here to save at least 9 with a 50/50 chance of saving the 10th (and tallest dwarf). I will explain it but for ease of explanation I will use binary 1 and 0 for black and white. Number 1 being black hat and number 0 being white hat. Let's say we got a (random) hat sequence of 0001011101 with the tallest dwarf on the right and the shortest on the left. While colluding prior to the distribution of hats the dwarfs agree upon even or uneven parity. This means the total amount of 1's (black hats) must be even or uneven including the parity bit. In this case the 10th dwarf will count as parity bit. So if we'll take an even parity, the number of 1's must be an even number in total. When the questioning starts the tallest dwarf will see the hats in front of him being 000101110. The tallest dwarf counts four 1's (black hats) so to make the parity even he has to say 0 (white hat). He will get killed but the dwarfs in front of him will know the parity bit is 0 so the 2nd tallest dwarf will see the hats in front of him as 00010111. He will also count 4 and knowing that the dwarf behind him said 0 he'll know that the total amount of 1's is an even number thus concluding he has a 0 (white hat) and will state he has a white hat. Same goes for the rest of the dwarfs and so 9 will be saved. The 10th would've been saved it the dwarfs agreed on an uneven parity. That's why there's a 50/50 chance the 10th will be saved. I'm pretty confident this is the answer but if you want to understand it better (maybe my explanation is a bit vague) go search for "parity bit" on the internet. @Kristen - you have so underthought it! What if the dwarf behind you says "black" and the dwarf in front of you has a white hat???? @JustJanek- Your solution is close, but not correct. Every dwarf needs to consider the parity of a number composed of all the following dwarfs and all the dwarfs behind. The first dwarf says the parity of the 9-bits number in front of him. Assuming that all the other dwarfs know the trick and they stay alive, each dwarf needs to compare the initial parity with the parity of an 8-bit number composed of the hats in front of him and the hats behind (assuming that the dwarfs behind gave the right answer), if the parity is the same, he knows that he has a white hat, otherwise he has a black hat. Show More Responses You can save 9 dwarves at least. Dwarves agree that the tallest one says he is wearing black hat if he sees odd number of black hats in front of him and he says white hat if he sees even number of black hats in front of him. So, the tallest one has 50-50 chance of survival and other dwarves survive 100%. What is the minimum number of dwarfs that can be saved with this strategy? 9 First of all, let's numerate the dwarfs as N1, N2, N3, etc. with N10 being the tallest. Now, N10 will state the color of N9 as his own answer, "My hat is WHITE". Based on this answer, N9 will state his color with a positive statement if the color of N8 is the same as his, "My hat is WHITE". Based on N8's answer, N8 knows that his color is WHITE, now, he will state his color depending on N7. Let's say N7 is black, so N8 will state, "My hat is NOT BLACK". N7 knows that his color is BLACK, but N6 is white, so he will use a negative statement, "My hat is NOT WHITE" and so on. Full example: N10 = BLACK N9 = WHITE N8 = WHITE N7 = BLACK N6 = WHITE N5 = WHITE N4 = WHITE N3 = BLACK N2 = BLACK N1 = WHITE N10: My hat is WHITE (Dies) N9 = My hat is WHITE N8 = My hat is NOT BLACK N7 = My hat is NOT WHITE N6 = My hat is WHITE N5 = My hat is WHITE N4 = My hat is NOT BLACK N3 = My hat is BLACK N2 = My hat is NOT WHITE N1 = My hat is WHITE N10 will have a 50/50 chances of survival... I'm sorry N10, I couldn't save you :'( What is the minimum number of dwarfs that can be saved with my strategy? - 10 My strategy doesn't make any unmentioned assumptions (such as equal number of white and black hats, etc). At the same time, it doesn't add any unmentioned constraints either. The strategy is simple to the point of appearing simplistic. But it meets all the requires. The strategy is: When asked, every dwarf answers "Not RED". This is not an incorrect answer and the Giant, if he were an honourable giant that is :), would have to let the Dwarf live. On a different page altogether, I went through all of the above answers. Not to sound patronizing, but some of the solutions were quite brilliant. I was thinking if I could even come up with that even after years of pondering. But I must admit, all of the above strategies are made by an outsider (ie. us) who is not impacted by this fate. Whereas in the casestudy, the strategy has to be devised by the 10 dwarfs, who face the impact of this strategy. Not to bring in factors such as emotion, the bell curve distribution of intelligence, and other such anal considerations. But I thought it was important to bring in Game Theory, and that all Dwarfs are rational, and that all rational people do not want to harm themselves in any way. In other words, when a strategy's success depends on the conformance to that strategy by ALL the participants, the strategy should also benefit ALL the participants if it is to succeed (or in the least, should not harm even ONE participant). In all the above strategies, since even in the best case scenario the poor Tallest Dwarf has only a 50% chance of living, can we assume that he would conform to this strategy? Each dwarf should pronounce color of hat of dwarf before him. This way they can save atleast 9 dwarf out 10. Well, Once the dwarfs are lined up in descending order. Without any kind of assumption, 9 people can be saved with a 50% probability of the 10th (tallest). Here is how it can be achieved, The strategy is to call the color of odd number of hat. Say for example, the tallest dwarf sees 3 Black and 6 whites, it will call out Black(it may or may not die with 50% chances). Now, the 9th tallest dwarf knows what the 10th dwarf could see and if it (9th) dwarf sees the same odd number of black hats, it will know it has white hat. Next, 8th dwarf knows number of odd (black) caps 9th dwarf could see and if it(8th) finds 1 less black cap, it would know it is wearing a black cap.. and so on. 10- White (calls out Black because it sees odd number of black hats) -dies(assume) 9- White (calls out White because it could still see 3 black hars) 8- Black (sees that there is one less black hat as mentioned by 9th, hence identifies that is wearing black) 7-White (calculates that 8th is wearing black and he could see 2 black, hence identifies itself wearing whiteO( 6-White 5-White 4- Black 3-Black 2-White 1-White Sorry if there is confusion in the way I have answered. all can b saved... They will exchange their hats in Circular form...person10 can see the person1 color of hat and after exchange every dwarf will tell color to their previous ones and person 10 knows the color before changing it from dwarf 1. d10->d9->d8->d7->d6->d5->d4->d3->d2->d1->d10 CIRCULAR EXCHANGE OF HATS First lets look at number of back and white hats...To satisfy the condition "black and white" hata there is minimum one black or white hat present. So its minimum (9 black & 1 white) or (1 white & 9 black) hat being distributed randomly amoung dwarfs. The story says dwarfs are alowed to speak before execution. Lets make a strategy of saying only one colour before execution eg) black or white. Minimum probability of (9 black & 1 white) hats and all the dwarfs say "white"...In this case one is saved but all nine dead. If all dwarfs say "black"..Nine are saved but one is dead. The same applies for the minimum probability of (1 black and 9 white)hats. Thus minimum one dwarf is saved and maximum nine dwarfs can be saved. If each dwarf say the colour of hat in front of him..(dwarf can hear previous answer) then at least five people are saved. |

### Customer Service REp at Yahoo was asked...

How many tennis balls are in this room and why? 14 AnswersThere is no correct answer to this question. It's all based on your problem solving abilities. The method for "solving" this involves making assumptions and then calculating an answer. The assumptions could be wrong, which isn't as important, and the interviewer will likely help guide your assumptions if they felt it was necessary. The assumptions here would be about the approximate size of a tennis ball, the approximate volume of the room, etc. Getting fancy, you might begin discussing how the weight of the tennis balls would begin compressing the lower levels, giving more potential room at the top, as well as how the second level of tennis balls would rest in a lattice structure on the first level, sitting in the gaps, and thus not being as high as simply multiplying the diameter of the tennis ball by 2 to get the height of two layers. I agree with both prior posts. An interviewer asking this question is trying to determine your problem solving skils. The worst thing you could do is blurt out an actual number without explaining your thought process. I'm not sure the interviewer is as interested in the quantity as much as how you arrive at it. The worst answer "Wow, I have no idea". Show More Responses Everybody is reading this question wrong. It doesn't say how many tennis balls CAN FILL this room. It says how many tennis balls are IN THIS ROOM and why. The question is probably meant to see if the candidate is actually fully paying attention to the questions (unlike everybody who has answered it here). It is a trick. I would gather to say that there are NO tennis balls in the room...and why? Because it is an office, not a tennis court. Hi wildfiresg, Maybe you should ask the interviewer to show the insides of his pockets? You never know, maybe there is a tennis ball in there! I think wildiresg is the only one above who's really paying attention (which is CRITICAL in an interview) - give him the job!! And Igor makes a very good but funny point....the candidate should also ask to check any drawers, boxes or closets in the room!!! In the original post the candidate did mention "how many tennis balls can fill this room?" as part of the interview. The first answers were tricked into reading this question as the same in the story. Good job wildiresg! "If the room is already filled with sand, none. Do you want to know if I can actually write code?" If the question really is how many "are in this room", then make an observation about how many you can see. I'm going to assume "zero" is a safe bet for most interviews. If, however, the question was suppose to be how many *can fit* in the room, then please ask (type, in this forum) the right question, or the people who are smart enough to actually listen to the question you're asking will never give you a response you'll be happy with. Assume: 1) this is a theoretical determination of how many the room would hold & 2) not an exercise of observation & 3) there is no compression ... then this is a simple mathematical problem (as long as you know the formulas) and you have the relevant metrics to hand. A tennis ball is a sphere & its volume is calculated at 4/3 Pi r(cubed). Packing ratios are 66 & 1/2% (there will be space between the balls when packed). With the dimensions of the room you can then calculate how many tennis balls would fit into it. This can be used to work out the fairground game of how many marbles in a jar or even m&m's in a jar (though that is a different formula & is for an oblate spheroid & not a sphere) This is a metaphorical question. There is one tennis ball in the room. The interviewer is serving and the candidate is returning. The game will continue until the ball is missed. As any schoolboy could tell you: count the number of chairs in the room and multiply by 4. The tennis balls are on the bottom of the chair legs so they don't scuff the floor! sound weird but they i want to be sure that u r focus Show More Responses metaphorical question..because there aren't balls in the room. but the balls are keeps on rolling, because it has its determination to keeping that ball rolling.. |