# Interview Interview Questions

interview questions shared by candidates

## Interview Interview Questions

How would you address a circumstance in which you disagree with your supervisor's decision or actions in a particular instance? 1 AnswerI responded that my responsibility is to provide my supervisor with sufficient info for her to make a good decision and ultimately I have to trust she is going to do just that, she won't ask me to do anything unlawful, and as she has the overall responsibility, I will need to accept her decision and move on with business to support her decision. |

### IOS Developer at Copper Mobile was asked...

What is iphone reference library? 1 AnsweriPhone reference library is a set of reference documents for iPhone OS. |

### Cabin Crew at Emirates was asked...

Why do you want be Flight Attendant? 1 AnswerThe reason is because I am a team player, love to interact with different people from all over and love to travel. |

### Software Developer Position at RockYou was asked...

Given 5 pirates on a ship, they need to distribute a pot of gold that has 100 gold pieces inside of it. The first pirate must make a proposal of how the gold will be distributed. If he receives over 50% votes from the remaining pirates, then his proposal will be accepted and the gold will be distributed. If he receives less then 50% support, then he will be thrown off the ship and die. 42 AnswersThe answer is for the first pirate to offer the 3rd and 5th pirates 1 gold each, and then take the remaining gold for himself. Otherwise the 3rd and 5th will probably not receive any gold. this is an extremely subjective question. first the nature of the pirates must be examined. if this is truly a team, then of course each pirate should receive 20 pieces of gold. however, if there is a division of labor that affords certain pirates greater responsibility then we are looking at a vertically stratified solution. in this case those at the top, the CEO's of the pirates, must be given more of the booty. if there is no stratification, but the nature of the pirates is individualistic and greedy, i would assume divide the gold into pirates 2 and 4 get 25 + you get 20 + pirates 3 and 5 each get 15. The first answer is right. You need to think that the pirates are rational and greedy for the most they can get. Then you need to consider what would happen with two pirates and take it from there. Show More Responses i disagree with the first answer completely. his proposal needs to have over 50% votes by the remaining pirates, not including himself. this means 3 out of 4 votes. if he proposes taking 98 pieces and the 3rd and 5th take 1 each, there's probably no way any of the 4 will vote for that proposal. since he needs 3 out of 4 votes excluding himself, that one nay vote can get snubbed altogether. assuming that the pirates want to maximize as much as possible, they will not mind the fifth pirate not receiving ANY gold. i suggest that the first pirate make one of the following proposals: - first pirate receives 1 gold so that the other 3 equally receive 33 gold pieces. the nay vote pirate will get 0. this carries the least risk of him getting kicked off. - first pirate receives 25 pieces as well as three other pirates. the nay vote pirate will get 0. the 3 other pirates voting for the proposal might view this as the most equitable solution among the four with one guy losing out. He needs to shoot the ring leader(dominant) of the remaining 4 pirates and re-negotiate after reloading. There isn't an optimal solution for the first pirate. The first pirate can't come up with a solution that will give 2 other pirates a maximum of the gold. The other pirates will always vote no unless the first pirate gives one of them all 100 pieces, since it's always in their best interests to dump the guy overboard and split it amongst less people. It's the wrong question. The question correctly stated is as follows: (credit to vorg.ca) Five buccaneers have obtained 100 doubloons and have to divide up the loot. The buccaneers are all extremely intelligent, treacherous and selfish (especially the captain). The captain always proposes a distribution of the loot. All buccaneers vote on the proposal, and if half the crew or more go "Aye", the loot is divided as proposed, as no buccaneer would be willing to take on the captain without superior force on their side. If the captain fails to obtain support of at least half his crew (which includes himself), he faces a mutiny, and all buccaneers will turn against him and make him walk the plank. The buccaneers start over again with the next senior buccaneer as captain. What is the maximum number of doubloons the captain can keep without risking his life? 20 pieces. The captain should divide the pie equally 5 ways (20 pieces). Then explain to the four pirates that anyone who does not agree to this fair deal of equal distribution will receive nothing, and that person's share will be retained by the captain alone. No one would want the captain to get their share. Everyone would think the deal fair. And therefore the captain's life would not be at risk at all. Be bold, be treacherous, be past tense: I took Pirate 2 and Pirate 3 aside. I told them, "We will split the gold evenly, three ways, between us. We three can overpower Pirate 4 and Pirate 5, so they do not receive any gold." Then I took Pirate 4 and Pirate 5 aside. I told them, "We will split the gold evenly, three ways, between us. We three can overpower Pirate 2 and Pirate 3, so they do not receive any gold." The vote was 100%, and I got away with all the gold, since each of the other pirates killed each other for being doublecrossed. Since I'm telling the story, it's clear I survived. Splitting the gold amongst 3 of the 5 pirates (1st pirate included) gets 50% of the remain pirate vote. In this way, the pirates get the most gold and there is a majority to vote against the first pirates death. Navy Seals kill all the pirates and return the gold to the rightful owner. Show More Responses The leader can keep 98 of the gold coins and give 1 to the 2nd ranked and 1 to the 4th ranked pirates. Let's assume 1st that they are so selfish that they care more about the money than each other's lives, and 2nd, that they follow this 50% rule without question. The lowest ranking pirate, number 5, has absolutely no reason to support any other pirates, because he knows that if all the other pirates walk the plank he gets 100 pieces. Pirate number 4 knows that if he's left with pirate 5, pirate 5 will demand all the booty or vote against the proposal to kill 4 and receive it anyway. Pirate 3 recognizes pirate 4's predicament and would only have to offer him 1 piece of gold so that 4 would come out better than being stuck with making the decision and losing everything. His support would provide 3 with a majority. If it came down to pirate 3's decision, he would have 99 pieces, 4 would have 1 and 5 would have 0. If the second ranked pirate, pirate 2, was faced with negotiating, he would need the support of 2 additional constituents. 5 will always vote against him, and 3 recognizes that he can make 99 pieces of booty if he's in control. In order to live, pirate 2 would have to offer pirate 3 99 pieces and pirate 4 1 piece, leaving him with nothing. Pirate number 1 similarly recognizes the predicament of pirate 2. Pirate 1 only needs two other supporters. That's easy. Better that pirate 2 receives his life and even one piece of gold than nothing. Pirate one offers him 1 piece of gold. Similarly, pirate 4 knows that he can get 1 piece of gold and his life, so pirate 1 offers him 1 piece of gold and has his support. After giving pirate 2 and pirate 4 one piece of gold each, he has their support and can take the remaining 98 pieces for himself. QED! Yeah baby! The rationale set forth by Marketing and Information Systems Major is well-explained and thought out, but with one fatal error (i.e. my user name). The interviewee is correct. Suppose that pirates are named by letters, with the most junior pirate in each scenario being Pirate A. I'll list the pirates in order of seniority for each case: In a two-pirate case (Captain, Pirate A), the captain always keeps the booty. Pirate A has no leverage whatsoever, since he'll never have superior force to remove the captain. In a three-pirate case (Captain, Pirate B, Pirate A), the captain only needs one vote. Pirate B wants to get rid of the Captain so he can be in the advantageous two-pirate case. Pirate A wants to AVOID that, so the Captain easily buys Pirate A's vote with one gold coin -- the status quo is maintained, and Pirate B gets shafted. In a four-pirate case (Captain, Pirate C, Pirate B, Pirate A), the captain still only needs one vote (a tie means no superior force, which means the status quo is maintained and the captain wins). We pose our standard question: "If the captain loses the vote, who gets shafted?" -- well, if the captain loses, it's a three-pirate case, which means Pirate B gets shafted. So the captain easily buys Pirate B's vote with one gold coin, and the status quo is maintained. Result: Pirates A and C got shafted. In the desired five-pirate case (captain, Pirate D, Pirate C, Pirate B, Pirate A), the captain needs TWO votes to avoid losing power. So we ask ourselves: "if the captain loses the vote, who gets shafted?" -- Pirates A and C (as determined above, in the four-pirate case). Therefore, to maintain the status quo, the captain proposes one gold coin to Pirates A and C each, and keeps 98% of the booty for himself. The downfall of these pirates is their inability to think laterally or deeply e.g. it's a machine question, not a human question. Subjective variables such as selflessness and morality would make these pirates much less predictable, forcing the captain to appease each and every one of them to the best of his ability, rather than knowing exactly whose vote to buy and at what price. by "deeply" i meant creatively, and by "e.g." i meant "i.e."!! edits would be awesome. The answer is 25. If they split it 5 ways, then its 20 each. If he needs 3 votes, offer each of them 25 and nothing to the last guy, then they will approve, since 25 is more than 20 (even split). Given that the first pirate needs the majority of the remaining vote (3/4) pirates. Then, First Pirate - 25g Crew Member 2 - 25g Crew Member 3 - 25g Crew Member 4 - 25g Crew Member 5 - 0g My logic behind this is simple. In order for their greed not to be outweighed by their survival the 4 pirates can share the booty equally with the 5th pirate as an example of the position they would find themselves in. 5th Pirate gets thrown of the ship and dies. It could stop here or they could revote, If they revote then, First Pirate - 33.3g Second Pirate - 33.3g Third Pirate - 33.3g Fourth Pirate - 0g Rinse and repeat until two pirates left sharing the loot 50g each. Wait, read the clue carefully. Let's say I'm the captain, and my pirates are 'greedy'. Option #1: I give myself and 4 pirates 20 gold each. That's good, right? Wrong. The pirates are 'greedy', and the 4 pirates will STILL vote to throw me overboard, because that would increase their 'take' to 25 Gold each, since I no longer get any. In order for me to WIN, I need to provide them with MORE than 25 Gold each, because that's what they will get for voting me off. Therefore: I keep 22 Gold, and I give pirates 1,2,3 each 26 GOLD. That means, if they vote me off, they will only get 25 Gold, and 26 is more than 25. Thus, the maximum I can keep is 22 Gold. BUT, if it only takes 2 Votes (i.e, my vote counts), then I keep 34 Gold, and give pirate 2 and 3 33 Gold each. Thus, my vote + 2 pirates >50% of the votes. Pirates 3,4 get zero. if they're going to kill you if you can't get 2 guys to back you up, then they can just as easily all four decide to kill you and then the remaining four are in the same quandry, but with only four shares. keep recursing until there is only one guy with all the gold. your only chance is to give them all the gold in the hope that they will deign to let you live, then kill them while they sleep and take it back. This problem really has no solution to it - as it clearly says the one who is proposing distribution doesn't get to vote! figure this: the lead pirate proposes a solution (98 for himself, 1/1/0/0 for others; or any other option) - but he doesn't get to vote. The others can always call this an unfair division and throw the helpless pirate out - as he doesn't have any say. Even if they decide to divide it as 20 coins each, the others can still throw the first pirate and maximise their share by 25% each - this can go on until the youngest/last pirate walks out with all the money. therefore this is an impractical situation. However, the whole situation changes if you allow the pirate proposing the distribution to vote!!! Then the solution, as proposed by some one above, of a distribution being 98/1/1/0/0 will eventually be accepted. Search for the pirate game on Wikipedia, the question is a straight lift of that puzzle - except that someone decided to change the problem by making the lead pirate non-voting.....and that will always make this problem non-solvable. PS: @ mktg and Systems major: Baby, you forgot to read the problem correctly and just googled it up!!! OK, so within the parameters as outlined, and assuming that this problem is recursive (after the first pirate doesn't get enough votes, he's killed, and they're faced with a 4-pirate situation), let's look at it thusly: They're all greedy, and they all know that the best way is to kill everyone else and grab all of the loot. However, to do this, they _must_ be the "lowest pirate" on the pole (the last one to be given the chance of dividing the loot). If this "pecking order" is fixed (everyone knows exactly how they stand), it is different from if it is random. Let's look at both. 5-Pirates, fixed order: In this case, then the proposal outlined by Gus and the others that results in Pirate 5 getting 98 coins, and 4 and 2 getting 1 coin each works out best. 5-Pirates, random order: This is different, as the problem then becomes how the order is established after each pirate gets killed. Everybody wants to be the Last Pirate Standing (tm) (Fox, call me for show marketing rights), but as the first one gets killed, there is increasing odds that they will be chosen next, and not be the LPS. Unfortunately, in the question as posted (5 nameless, rank-less pirates) we don't know how pirate 5 got chosen to choose, and we don't know how pirate 4 will be chosen after pirate 5's demise. In this case, Pirate 5's best play would be to give two pirates 34 gold (one more than 33, and him take 32) if only two votes are needed, or give three pirates 26 gold (one more than 25, and him take 22) if a majority vote is needed, and hope that they would see this as fitting, instead of being the next sap in the position of making a 4-way split or his life. Show More Responses As stated the answer is: 25 gold pieces should go to any three pirates, with the leader keeping the remaining 25 for himself. Note - Gus' solution is incorrect because he assumes that the leader can vote on his own proposal. The leader can't. Also - as some others have pointed out, this probably isn't the right question. The question with a "succession plan" has a more interesting answer. Here is the detailed reasoning: So - I start by assuming that for all pirates, its infinitely more important to be alive than to get any gold, but if they are alive, they want as much gold as possible. The pirates, other than the leader are "unorganized", and all things being equal, they would rather have as many pirates around as possible. These are risk adverse pirates :) Assume there was one pirate: the best proposal - take all the gold for himself, which would definitely pass. If there were two pirates, unless the leader proposes to give all of the gold to other pirate, his companion will vote against it, and take all of the gold. If there are three pirates: if the other two pirates have a 50% of getting nothing and a 50% chance of getting 100 gold. So the expected value for both them is 50 gold pieces. He needs two votes to stay alive, so offering either of them less than 50 will assure losing a vote, and thus his life. Therefore, the leader proposes 50 gold to each of the other pirates, and stays alive. If there are four pirates: The remaining pirates have a 33% chance of getting nothing, and a 66% chance of getting 50 gold pieces if they reject the leader's offer. Their expected value is 33 gold pieces each. Offering any two of them 33 gold pieces, and with the leader keeping 34 is a proposal that should pass. If there are five pirates: for the four remaining pirates, they have a 25% chance of getting 34 gold pieces, a 50% chance of getting 33, and a 25% chance of getting nothing if they reject the leader's proposal. Their expected value is: 25 gold pieces. Since three votes are needed, 25 gold pieces should go to any three pirates, with the leader keeping the remaining 25 for himself. Are you joking? Pirates aren't fair! One pirate cheats all the others and splits with all the booty AND your women... They're pirates for chrissake! If I were the 1st pirate, I'd consider that goal #1 is to stay alive - my life is worth more than all the gold. So I'd propose that each of the other four pirates would receive 21 pieces of gold and I'd keep 16... and my life. Odds are that the other pirates would find this acceptable, and they may even keep me around to make the first proposal again next time. It's a win-win. We all keep our lives and get more gold than we had before. I can't speak for other pirates, but that's what I'd do. The proposal has to be accepted by two of the four other pirates. The only way the first pirate can do this is interview each of the other pirates individually and ask what they think is fair. His objective is to find two that are similar enough that he can modify the two into one plan. After mofifying the two plans into one plan he then goes back and asks these two individually again if the modified plan is acceptable. If he can get these two to accept the modified plan then he presents it. It doesn't matter what the other two pirates who were left out think because he has the two votes he needs. There's a pot of gold no one's seeing. The end game is that the last two will share 50 gold pieces each (no majority to mutiny). So pick two friends, offer them the 100 gold pieces between them, and hope they give you some afterward (but don't bet on it). Keep the gold pot and the friends. You lose two votes from those disenfranchised, but you and two friends hold majority might. Here's my thought about this. 100 gold to be distributed to 5 pirates The first pirate proposes how it will be distributed. He has to get 3 out of 4 votes in order to stay alive, otherwise he will be thrown out of ship and die. Let's say pirates are in nature greedy. Second/third/fourth/fifth pirate will rather kill the first pirate to accumulate more share of gold. If the first pirate proposes anything that doesn't let him get even a gold, his proposal might be accepted and he will remain alive. Ofcourse it might not be what will happen. The other pirates kill the first pirate and they quarrel over the pot of gold. The last-man-standing gets everything. Or they all die and no-one gets anything. The answer is 97. Start with three pirates. I was once faced with this very same dillemma...I ended up splitting the gold between three of the other pirates, which got me the vote I needed. Yargh, but then me and me accomplice, the man without any gold, we shivved all the rest and threw the bodies overboard, each claiming 50 gold, yar! Attach the gold to a life preserver and throw it overboard . If they are so greedy they will all dive after it. You sail away with the ship and sell it for much more than 100 pieces of gold. First, you must realize this is not just a logic question with one right answer, but a way for an employer to probe you thinking process as you talk out loud. So if you make stupid assumptions like “I’m the captain so they will let me have more” or “I will just kill them later” or “I would strike a side deal”, then you will be looked at as a dodger or lazy or scared to address the question, so that crap is out in an interview. You might get points with this one good assumption: “It looks like the question is incomplete, I assume that the voting rounds continue until an offer is accepted or only one pirate is left.” Facts: in round 1 the offeror needs 3 of 4 votes for a majority. In round 2 he needs 2 of 3, in round 3 he needs 2 of 2 and in round 4 he needs 1 of 1. (So now you are showing the interviewer you are thinking ahead before rushing off trying to give the answer). So the offeror in the first round wants to maximize his gold and his chance of living. So he makes this offer. 33 Gold to each of 3 voters and 1 for himself. He explains why this is the best they can hope for as such. In the final round, the 1 voter either gets 100 pieces of declines the offer, kills the pirate and takes 100 anyway. He can even legally decline the offer of 100, kill the pirate and still take 100 pieces. Now you may think this is good, but the odds of one of the 4 of you being alive and being the voter is 1 in 4 or 25% (see mister interviewer, I can to simple math). So you have a 25% chance of 100 pieces, or 25 on average, so 33 and guaranteed life now is a better deal, in fact you should be happy if I offered you 26. But I want to take just one, so in the next round, the offeror will have to take 1 or less or face certain death, because he saw me die for just 1. In the next round, that means the 2 winning voters will want 50 pieces each. But they only have a 50% chance of being 2 of the 4 people being offered gold. That means they have a 50% chance of getting 50 pieces, on average, they get 25, again less than 33. If they want to try to make it to round 3, there will be 1 offeror and he will have to get both votes for a majority to live, so again he will have to be willing to give 50 to each. From round 1, the 4 have a 50% chance of being a voter now and a 50% chance of being dead or getting 0 and living. If they get 50 pieces, then 50% of that is 25. Still less than 33. Also, the offeror can argue that if they don’t accept his offer, then one of them will die and/or get 0 in next round, the other will get 100, but at this point on average would get only 50. So he might be willing to offer each much less then 50 to guarantee they live, so now they are worse off. In no average case are they better off than taking your 26-33 piece offer and the certainty of life. (Now, if I am the first offeror, I will probably max out their offer at 33 so I maximize my chance to live and fight another day). Or you just pull out your light saber and kill the other 4. Show More Responses You need to look at the question from the end first. As each pirate is thrown off the ship, there are fewer pirates to split the gold up with. At the end there will be 1 pirate who gets all 100 pieces of gold. Pirate 5 1 pirate 100 With two pirates, the situation looks like this: Pirate 4 Pirate 5 2 pirates 0 100 1 pirate 100 Pirate 5 has no reason to accept any offer other than all the gold, since if he rejects Pirate 4’s offer, he will get all the gold, anyway. With three pirates: Pirate 3 Pirate 4 Pirate 5 3 pirates 99 1 0 2 pirates 0 100 1 pirate 100 With 1 or 2 pirates, Pirate 5 has all the power, but with three pirates, 1 piece of gold for Pirate 4 is better than any of the other conditions. With four pirates: Pirate 2 Pirate 3 Pirate 4 Pirate 5 4 pirates 97 0 2 1 3 pirates 99 1 0 2 pirates 0 100 1 pirate 100 With four pirates, Pirate 4 and 5 get a better deal than with 3 pirates. With five pirates: Pirate 1 Pirate 2 Pirate Pirate 4 Pirate 5 5 pirates 97 0 1 0 2 4 pirates 97 0 2 1 3 pirates 99 1 0 2 pirates 0 100 1 pirate 100 Pirate 3 and 5 get a better deal than with 4 pirates. I have just a few things to add that seem logical in order to know how to determine the answer. The most important thing to know is whether they are distributing the gold while at sea or near land (or in port). If they are at sea there is a far greater likelihood that the captain would survive regardless of the distribution, since it takes several people to man a ship. If they are near land, the answer can only be determined by knowing the personalities of the crew and how much fear or respect the captain commands. The more fearsome the captain is, the less likelihood of a mutiny regardless of the division as long as each of the subordinates received an equitable portion and the captains share was not overly large. The idea of 'friends' among pirates is ludicrous- pirates by nature form alliances merely for numbers, and are by defination treacherous. The idea of trying to solve the problem mathmatically is interesting but unsubstantiated as the outcome of gold division vs staying alive would invariably be determined by the variable factors I outlined above. By solving the problem through manipulating the pirates desire to be the only one left alive, there is an underlying assumption that only one pirate is necessary to sail a large vessal at sea, which is not the case, and even pirates know that. you find the solution by starting from the opposite end. Start with the scenario where only pirate D and E remains alive. Then D will keep everything to himself. Knowing this (if C was alive) he would offer just one gold coin to E (since he knows what happens if they choose to kill C - then E gets nothing). Continue to the point where A is still alive and you'll find: A=98, C:1, E:1 The question should also be that: if the top ranked pirate dies, then the whole process is repeated for the 4 remaining pirates, and so on: if the 2nd ranked pirate dies, it is repeated for the 3 remaining pirates... and so forth... And the answer should be that if all pirates are strictly purely logically and think for himself only, then the top pirate will get 98 coins. This question seems to suggest 2 things: 1) Since the top ranked pirate can get the most gold coins, it justifies why the top person in a company get most of the money and the fraction of the fraction is left for the people underneath. 2) Since it assumes that people underneath will not team up, maybe that's why in some companies, it is the benefit of the top for the people underneath not to be in good relationship, so that it mimics the situation above, so that the top person can get most of the gold coins. also note that if makes a difference whether if 50% of the vote is established, whether the top pirate die or whether the proposal is accepted. > 2) Since it assumes that people underneath will not team up, maybe that's why in some companies, it is the benefit of the top for the people underneath not to be in good relationship, so that it mimics the situation above, so that the top person can get most of the gold coins. so those companies will actually want to foster a bad relationship between people underneath. And will that company want to hire "good guys" for the company? No, because the good people are good with each other and can team up. If there are many many bad guys, then they will be all greedy and hate each other and think for themselves only and not team up. Therefore, the company may want to hire bad guys instead of good guys. this is a trick question. if the point is to guarantee that he stay alive, he needs to make 3 pirates as happy as possible. the only way to do that is to split the entire share evenly between them. this means excluding one pirate AND HIMSELF. "Anyone who's with me and votes for my proposal gets an equal share of gold. Vote against me, and you get nothing while the rest of us gets an even more equal share of the booty." Assume you are the pirate who distribute the gold, you just put the gold to a heap one by one and let the rest pirate to decide when to stop picking, the first person who says 'stop' will get the whole golds in this heap and the others must distribute the other golds. |

Consider an X x Y array of 1's and 0s. The X axis represents "influences" meaning that X influences Y. So, for example, if $array[3,7] is 1 that means that 3 influences 7. An "influencer" is someone who influences every other person, but is not influenced by any other member. Given such an array, write a function to determine whether or not an "influencer" exists in the array. 12 AnswersThis was a tough one that forces you to consider how best to traverse the array and eliminate possibilities as soon as possible. Not_Influencers[n] = 0; //Make all elements 0 for (i = 0 ; i< n ; i++){ if(Not_Influencers[i] == 1) continue; row_sum = find_row_sum(a[i]); if(row_sum == n-1 && find_col_sum(i) == 0) return Found; for(j = i; j < i; j++) if (a[j] == 1) Not_Influencers[j] = 1; } X should be equal to Y, right? Show More Responses //if vec[i][j] == 0 then i is not an influence //if vec[i][j] == 1 then j is not an influence //so time complexity is O(n) bool find_influences(vector > &vec) { int n = vec.size(); vector not_influence(n); for (int i = 0; i = 0; --j) { if (!vec[i][j]) { break; } not_influence[j] = 1; } if (j < 0) { return true; } } not_influence[i] = 1; } return false; } Run a BFS or DFS. For each node keep going to influencer. Find a node which can be reach by all nodes. Sort of finding sink node. public static int influencer(final int[][] jobs, final int r, final int c) { int[] degree_in = new int[jobs.length]; int[] degree_out = new int[jobs.length]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { if(jobs[i][j] == 1) { // i influences j degree_out[i]++; degree_in[j]++; } } } for (int i = 0; i < r; ++i) { if (degree_out[i] == r - 1 && degree_in[i] == 0) { return i; } } return -1; } Consider the input as Graph given in adjaceny matrix representation. Find whether a semi-eulerian path is present in the graph or not. Take the XOR product of the original matrix with the transposed matrix and sum by row. If any row counts equal the rank then they are influencers. private static boolean hasInfluencer(int[][] matrix) { if (matrix == null) return false; if (matrix.length == 0) return false; boolean result = false; for (int i=0; i the XOR suggestion I think is incomplete. The condition sum(row_influencer) = 1 and sum(column_influencer) = N so a simple matrix multiplication with the transposed should give for the vector v[influencer] = N and v[N-influencer] = 1. I assume influencer influences himself. def find_influencer(matrix): for row in range(len(matrix)): following_none = not any(matrix[row]) if not following_none: continue all_following = True for r_no in range(len(matrix)): if not row == r_no: continue if not matrix[r_no][row]: all_following = False break if all_following: return row return -1 Here is a different view. Please comment if you find any issues with the logic. 1st. condition: An influencer can not be influenced by any one. Let's say the in a matrix of [x.y], there is an influencer with index 2. So, the column=2 (3rd column) in the matrix must be all 0s, since the influencer can not be influenced. Step 1: Find a column with all 0s. If found, remember the column index or there is no influencer. Let's say, it is m Second condition: An influencer must have influenced everyone. So, in our example: row=2 (third row) must be all 1s except for column=2, since influencer can not even influence self. Step 2: Check row=m and find that all values are 1 except for [m][m]. If found, we have an influencer. |

### Technical Program Manager at Amazon was asked...

Given a string like "I'm being interviewed by Amazon" implement a method that reverses the given string so that it looks like "Amazon by interviewed being I'm". 8 AnswersIn java: String str = "I'm being interviewed by Amazon"; String pieces[] = foo.split(); String reversedFoo; for (int i = pieces.length - 1; i >= 0; i--) { reversedFoo += pieces[i]; if (i > 0) reversedFoo += " "; } System.out.println(reversedFoo); we can first reverse the whole string, and then reverse the individual words O(n) complexity /** * Jun Zheng, Rice Univ * An interview question of Amazon * Java 7, Eclipse * Reverse a sentence, e.g., "Amazon is so gay" to "gay so is Amazon" * @param str * @return */ private String reverseSentence(String str){ str=new StringBuffer(str).reverse().toString(); int j=0; for(int i=0;i<str.length();i++){ if(str.charAt(i)==' '){ String s1=str.substring(j, i); s1=new StringBuffer(s1).reverse().toString(); str=new StringBuffer(str).replace(j, i, s1).toString(); j=i+1; } } String s1=str.substring(j, str.length()); s1=new StringBuffer(s1).reverse().toString(); str=new StringBuffer(str).replace(j, str.length(), s1).toString(); return str; } Show More Responses Private String ReverseStr(String reverseMe){ StringTokenizer st = new StringTokenizer(reverseMe); int count; String[] iamReversed = new String[j=st.countTokens()] while(st.hasMoreElements()){ } } Pressed tab and enter and my comment got posted beofre even i could complete the code. here goes the complete method, Private String ReverseStr(String reverseMe){ StringTokenizer st = new StringTokenizer(reverseMe); int count; String[] iamReversed = new String[j=st.countTokens()] while(st.hasMoreElements()){ iamReversed[--j] = st.nextElement().toString()+" "; } return iamReversed; } int main() { string s; cout << "Enter string: "; getline(cin,s); string newstr; int spaces = 0, pos, start = 0; for ( int i = 0; i < s.length(); i++) if (s[i] == ' ') spaces++; for ( int i = 0; i < spaces; i++) { pos = s.find(" ",start); newstr = (s.substr(start,(pos-start))) + " " + newstr; start = pos + 1; } newstr = (s.substr(start,(s.length()-start))) + " " + newstr; cout << newstr << endl; return 0; } One liner in Python: def reverse(str): return " ".join(str.split(" ")[::-1]) 3-line solution in PowerShell: $str = "I'm being interviewed by Amazon".Split() $([array]::Reverse($str) ) [string]$str |

### Technical Program Manager at Amazon was asked...

Given two arrays find all the points of intersection between the (i.e. equal elements) and return them in an array. 4 Answerscouple of solutions - sort the array (nlogn) complexity - browse with the smaller array and visit each of the bigger array and return if there is a match. Complexity (n square) thus not a good solution next solution - sort the arrays and remove duplicates (nlogn) - create a table, with the longer array - browse to the smaller array and update the count - use a hashtable. O(n). traverse first array: O(n) put elements into hashtable: O(1) traverse through second array: O(m) check for existence of element in hashtable: O(1) if yes, add to resultant array. return resultant array So, final time complexity is O(n) Show More Responses def intersect(a1, a2): return [x for x in a1 if x in a2] One-liner in Python |

### Front End Cashier at Walmart was asked...

Name a problem you had with a supervisor or teacher. What happened and how did you overcome it? 2 AnswersI've never had a problem with a supervisor or teacher. My college history teacher taught in a largely lecture oriented way. We didn't have many assignments that would let us and the teacher know if we understood the material. I had a meeting with him after class one day and asked him if their were any ways I could check to make sure if i understood the material. He told me anytime I believed i didnt understand a topic just to speak with him shortly about it after class. |

How do you change a list of words in a file from slug format to Capitalized words? (ie police_officer to Police Officer) 2 Answerssed -e 's/^./\U&/' -e 's/_./\U&/g' -e 's/_/ /g' /path/to/input |sed 's/\(^.\)\([a-z].*\)\(\_\)\(.\)\([a-z].*\)/\U\1\L\2 \U\4\L\5/' |

If you could describe yourself in two words what would they be? 2 AnswersI described myself as driven and compassionate I describe everyone as a progress for the future. |