# Companies matching "Apple"

## Apple Interview Questions

### Software QA Engineer at Apple was asked...

There are three boxes, one contains only apples, one contains only oranges, and one contains both apples and oranges. The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels. Opening just one box, and without looking in the box, you take out one piece of fruit. By looking at the fruit, how can you immediately label all of the boxes correctly? 40 AnswersAll the three boxes are names incorrectly. SO the bax lebeled Apples+Oranges contains only Oranges or Only Apples. Pick one fruit from it. If it is Orange then lebel the box as Orange. So the box lebeled Oranges contains Apples and the remaining contains both. Label the boxes fruit. The key bit is "All the three boxes are names incorrectly" so the label on the box which fruit comes from will need to be changes to one of the other 2 labels. It can only be 1 of them (and it will be obvious when you have the fruit) then the remaining box (that hasnt featured yet)...Just swap that label with fruit box that was originally on the box which you took the fruit out of Thats hard for anybody to understand somebody elses explanation... eaiest way is to just do an example Show More Responses Swaz answer is almost correct however it does not work in all scenarios. lets assume: box 1 is labelled Oranges (O) box 2 is labelled Apples (A) box 3 is labelled Apples and Oranges (A+O) and that ALL THREE BOXES ARE LABELLED INCORRECTLY" Pick a fruit from box 1, 1) if you pick an Orange: - box 1's real label can only be O or A+O - box 1's current label is O - since ALL LABELS ARE INCORRECT then box 1's real label can not be O - box 1's new label should then be A+O by elimination - since ALL LABELS ARE INCORRECT - box 2's label is changed to O - box 3's label is changed to A - SOLVED 2) if you pick an Apple: - box 1's real label can only be A or A+O - box 1's current label is O - since ALL LABELS ARE INCORRECT then box 1's real label can not be O - this still leaves us with the choice between label A and label A+O - which would both be correct - FAILURE Solution: The trick is to actually pick a fruit from the A+O labeled box Pick a fruit from box 3: 1) if you pick an Orange: - box 3's real label can only be O or A - box 3's current label is A+O - since ALL LABELS ARE INCORRECT then box 3's real label can not be A+O - box 3's new label should then be O by elimination - since ALL LABELS ARE INCORRECT - box 1's label is changed to A - box 2's label is changed to A+O - SOLVED 2) if you pick an Apple: - box 3's real label can only be O or A - box 3's current label is A+O - since ALL LABELS ARE INCORRECT then box 3's real label can not be A+O - box 3's new label should then be A by elimination (not O) - since ALL LABELS ARE INCORRECT - box 1's label is changed to A+O - box 2's label is changed to O - SOLVED it only says you can't look, doesn't mean you can't feel around or smell the fruit you picked, easy deduction after you figure the first box out Sagmi is right, but did not give the full reasoning. "the bax lebeled Apples+Oranges contains only Oranges or Only Apples. Pick one fruit from it. If it is Orange then lebel the box as Orange." so far so good Now, the box labelled Apples cannot be the box containing only Oranges, you've just found that box, so it must contain Apples and Oranges. And in that case the other box, labelled Oranges, must contain only Apples. It's easier to draw it out. There are only 2 possible combinations when all labels are tagged incorrectly. All you need to do is pick one fruit from the one marked "Apples + Oranges". If it's Apple, then change "Apple + Orange" to "Apple" The "Apple" one change to "Orange" The "Orange one change to "Apple + Orange" If it's Orange, then change "Apple + Orange" to "Orange" The "Apple" one change to "Apple + Orange" The "Orange" one change to ""Apple" Since all 3 boxes are labled incorectly Start with the box Labled A&O. If Its apples than the box labled apples then the apple one is oranges and the oranges is O&A. Label each box "Apples and/or Oranges" and the all will be correct. This is very simple to resolve. I was asked the same question at FileMaker. Each box is incorrectly labeled. So you go to the box that is labeled "Oranges and Apples" and take one out. It doesn't matter what comes out because all that you know is that it is not AO. If you remove an Apple then move the Apple label to it. Since the Apples are already identified it is easy to resolve the rest. All you know for certain is that the other two boxes remaining are mislabeled. So the AO label goes on the box with the remaining label and that label goes on the Apple box as you have already assigned that. The end result is you only need to remove one piece of fruit to figure out the proper locations of all. Go down the road to HP. Maybe they are hiring. Some of these pseudo-problem solving questions like this are bunk. I was once asked why sewer covers are round and not square. I gave the correct answer without even hesitation and the interviewer seemed put off that I knew the answer. I didn't get the job but, in hindsight, no great loss. I prefer the questions (like the basketballs one from google) where you won't be able to give an accurate numerical answer but by explaining HOW you would go about solving the problem is all you need to do and MAYBE shows your aptitude for problem solving. Smell the box you opened. Step 1: Order the boxes by weight. Either apples weigh more than oranges, or oranges weigh more than apples. The mixed box will always be in the middle. Step 2: Open the first box, take out the fruit and look at it. Step 3: If the fruit is an apple, deduce that the middle is apple and oranges and that the third box is oranges. If the fruit is an orange, then deduce that the last is the box with the apples. Show More Responses Donna is the only one with any common sense. The problem with corporate America, is that it's run by a bunch of Bozos who over complicate things and have a narrow to zero vision on how to solve even the simplest problems. I can imagine that most of you would get a committee, have long meetings where you talk about 'think out of the box', and 'at the end of the day' nonsense. This is an interesting logic question, but I would not want to buy fruit from a company who knew they had a problem and then sampled one out of three boxes to resolve the issue. There are other correct answers posted. I'll just make a comment: "The boxes have been incorrectly labeled such that no label identifies the actual contents of the box it labels." Nothing in the above statement says the labels are limited to oranges/pears, only that they do not identify the contents. They could say 'nuts', 'bolts', etc. Technically, all answers should be prefaced with: assume that the labels say 'oranges', 'pears', and 'orange/pears'. Ok, the problem does not make sense and is unsolvable if the labels say 'x', 'y', 'z', but someone with (likely with a math proof back ground) may appreciate attention to detail. Q: Why do posters denigrate the interview questions? The questions, however stupid they may be, are a opportunity to show you can build an answer. Even if you pursue an invalid train of thought in the interview, it's a thought. It's what they want to see and what will help you get a job offer. Note: I also would not assume that the questions asked are a reflection on the company, department, or team as a whole. It may just be the interviewer that has chosen poorly. So to say "I don't want to work for company X because they asked me a stupid interview question" is pretty closed minded. To even think I don't want to work with that interviewer just based on questions asked seems extreme. rightly pointed out by Sagmi ... this question was put forward to me at Huawei Technologies and that was the answer I gave So the question was asked at an interview for Apple: Label ALL the boxes apple and charge a ridiculous price for them! Just label all of them "Fruit." Put another way, it is not possible to tell since we don't know how the boxes are mis-labled. What if the Apple box was labeled Oranges and both the other boxes were labeled Apples and no box was labled Apples and Oranges? You might have assumed there are three different labels when their might have only been two different labels. Always pict a piece of fruit from the box labelled Apple&Orange. As we know that this label is wrong, there are two possibilities: If it is apple, then wo know that this box should be labelled Apple, so we switch Apple label with the label Apple&Orange. Then Apple label is correct. We also know that the Orange label is incorrect, so we then switch Orange label and Apple&Orange label. if it is orange, then we know that this box should be labelled Orange, so we switch Orange label with label Apple&Orange. Then Orange label is correct. The same as above, we know that the Apple label is incorrect, so we switch Apple label and Apple&Orange label. If all boxes are labeled incorrectly and u pick a orange out of a box that's labeled apple/oranges change the name to oranges then change the box labeled oranges to apples and the the box labeled apples to apple and oranges... If you pick a apple out of a box labeled apples and oranges change the name to apples and then change the box labeled apples to oranges and the last to apples and oranges... If u pick a apple out of a box labeled oranges change it to apples and oranges then the box labeled oranges to apples and the box labeled apples to oranges...if you pic a orange out of a box labeled apples change it to apples and oranges and the box labeled oranges to apples and the last to apples and oranges... See the pattern? I think there is a big box and it contain two small boxes and all the labels are incorrect so big one contain two boxes that makes it carrys both orange and apples and in that thwo boxes having orange and apple respectively so if we open any box we can label it correctly Show More Responses To see the java source code of puzzle, visit: https://github.com/SanjayMadnani/com.opteamix.microthon code is taking the input by console only. You can fork or clone the repository and proceed further. You can also rise bug if you find any. Run BasketPuzzleGameTest.java class as a Junit test case to start game. if it known already that boxes labeled incorrectly, I would give it back to those who did label them and ask to fix this confusion. it is impossible to tell by opening only one box, so you have to open one more box. As mentioned already, if you start with the A+O bucket, you can solve the puzzle by pulling only one fruit, Bucket: A+O Found: A Bucket A+O > A | A+O, but since A+O label is incorrect, then it must be A Bucket O > since A is taken, the new label must be O | A+O, but since O is incorrect, it must be A+O Bucket A > since A and A+O are taken, it must be O Bucket: A+O Found: O Bucket A+O > O | A+O, but since A+O label is incorrect, then it must be O Bucket A > since O is taken, the new label must be A | A+O, but since A is incorrect it must be A+O Bucket O > since O and A+O are taken, it must be A If you are lucky, you might solve it with just one fruit even if you start with other buckets, Bucket: A Found: A Bucket: A > A | A+O, but since the A label is incorrect, it must be A+O Bucket: O > A | O, but since the O label is incorrect, it must be A Bucket: A+O > since A+O and A are taken, it must be O Bucket: O Found: O Bucket: O > O | A+O, but since the O label is incorrect, it must be A+O Bucket: A > A | O, but since the A label is incorrect, it must be O Bucket: A+O > since A+O and O are taken, it must be A If you start with the A bucket and pull an O or if you start with the O bucket and pull and A, then you are SOL and you need to pull out more fruits to figure it out. 1. Open one box and check its contents. 2. Remove the current label and apply the correct one (by removing it from one of the other boxes) 3. Since all boxes have been labeled incorrectly, switch labels between the other 2 boxes. And Voila you have all the boxes labelled correctly :) In requirement already specify that all three box labels are not correct. A+O A O Step1: First Pick an item A+O Box. If you get an Apple then it is a Apple Box. swap the label . A A+O O AS we already know in the box that label with Orange, does not contain Orange because of wrong label. So It must contain A+O. Just Swap the label A O A+O OK, all 3 boxes are incorrectly labeled. Open the one that says apples and oranges. Whatever is in there is what it is (since it cannot be apples AND oranges). Now, if there was an orange in there, apples must be in the orange box (since they cannot be in the apples box), and apples and oranges in the apples box (due to process of elimination). Get it? I guess questions like these will appear easy if you put them on paper, it is the possible combinations that become relevant, one way to approach is.. One of the key factor is all boxes are labelled incorrectly, this gives rise to only (2) combinations right To label for 1st box incorrectly you will have (2) options, once you label it then you have only choice to label the other two boxes incorrectly so 2 x 1 = 2 combinations possible i.e. Incorrect lablling options { Boxes_with_Oranges, Boxes_with_Apples, Boxes_with_Apples&Oranges } = { A, AO, O} or {AO, O, A} 2. To know for sure the contents of the boxes, you need to pick the box with either Apples or Oranges and avoid box with Apples and Oranges. So from the (2) combinations you could pick a fruit from Box_labeled AO (this will contain either Oranges or Apples) So, if you get a Orange, it means that combination is{AO, O, A} , so that means Box_with_Label_O has Apples, Box_with_Label_A has Apples and Oranges Box_with_label_AO has Oranges or else if you get a Apple that combination is {A, AO, O}. Box_with_Label_AO has Apples, Box_with_Label_O has Apples and Oranges Box_with_label_A has Oranges Then you can correctly label all the 3 boxes. First answer in this post is correct, as its said all boxes doesnt reflect correct items in it, If an apple is picked from a box , then it can be from either A/O box or A box, if the box is names A/O the, the label of the box has to be changed to A, then other two box labels to be accordingly. It is interesting that in 6 years people keep overthinking this. The answer is in the question and the criteria are that the boxes are immediately labeled and they are labeled correctly. ANSWER: FRUIT FYI you don't even need to open one box. Show More Responses Your choice going to be (( 2 apple 1 orange)) or (( 2orange 1apple )) . It can be recognize only one box (x) . U have to chose again until u get another formula then u will named easly . Step 1: Open a box labeled ‘Apples and Oranges’. We know that this box does not contain ‘Mixture’ for sure. If this fruit is an apple, then label this box as ‘Apple’. Step 2: (Very important) If we look at the box labeled as ‘Oranges’, we know that since the label is incorrect, this box either has only apples in it or has Mixture. Since we already know which box contains only apples, we know that the box labeled as ‘Oranges’ contains ‘Mixture’. So label it as ‘Mixture’. Step 3: (Very easy) The 3rd box will be labeled as ‘Oranges’. When you put your hands on the box to pick the fruits by touching every fruits you can feel whether all are apple or oranges or both and just pick one to see.So it is not necessary to pick one fruit and see whether it is orange or apple also it is not said in question that you can touch and feel all the fruits inside the boxes without taking it out .and then you can fix the label correctly on the boxes. Absurd, no logic km I will took a pen and stab the apple. and then ? apple-pen. Smelling the box and writing the correct label on each. :) Just label the boxes correctly. |

### Software Engineer at Apple was asked...

You have a 100 coins laying flat on a table, each with a head side and a tail side. 10 of them are heads up, 90 are tails up. You can't feel, see or in any other way find out which side is up. Split the coins into two piles such that there are the same number of heads in each pile. 36 AnswersAnswer #1: Place 50 coins into two piles on its edges so that both have the same amount of heads in each pile, neither facing up or down. Answer #2: Trick question, place 50 coins in both piles and in theory they all have heads just not necessarily facing up or down. agree with 2nd ans Split into two piles, one with 90 coins and the other with 10. Flip over every coin in the pile with 10 coins. Show More Responses Just split into two piles, each with 50 coins. The question only asks 50 heads in each one, it doesn't ask for the number of heads up!!! Pick 10 coins from the pile, flip it and put it in the other pile. This will ensure that the number of heads up are equal in both the piles Pick 10 coins from the original 100 and put them in a separate pile. Then flip those 10 coins over. The two piles are now guaranteed to have the same number of heads. For a general solution of N heads and a total of M coins: 1.) Pick any N coins out of the original group and form a second pile. 2.) Flip the new pile of N coins over. Done. Example (N=2, M=6): Original group is HHTTTT (mixed randomly). Pick any two of these and flip them over. There are only three possible scenarios: 1: The two coins you picked are both tails. New groups are {HHTT} {TT} and when you flip the 2nd group you have {HHTT} and {HH}. 2.) The two coins you picked consist of one head and one tail. New groups are {HTTT} and {HT} and when you flip the 2nd group you have {HTTT} and {TH}. 3.) The two coins you picked are both heads. New groups are {TTTT} and {HH} and when you flip the 2nd group you have {TTTT} and {TT}. The question says "'You' can't feel, see or in any other way find out which side is up....' Can a team member? Cooperate with a fellow engineer, or other colleague, who can see the coins to solve the problem? Question has its answer in it... 10 coins are head up..... 90 coins are tail down..... so it means all 90 coins are head up.... Now, all you have to do is to split it into half. 50/50 Let's generalise the question to where there are n heads and any number of tails on the table. Select any n coins. This set will contain m heads, where m is between 0 and n inclusive, and n - m tails. The other n - m heads will be in the remaining coins. We now have two piles: the selection of n coins with n-m tails and the remainder with n-m heads. All we have to do is flip the selection so that the n-m tails become n-m heads, the same number as the heads in the remainder. This is a straightforward extension of the 'pick any 10 coins and flip' answer correctly given above by several people. All of you are over thinking it. Read the last bloody line, "Split the coins into two piles such that there are the same number of heads in each pile" They're not asking for the heads to be up or down, just an equal amount & every coin has a head side so dividing the pile equally achieves that. 100 coins total, 10 of them are heads up, 90 are tails up. Meaning all of them are heads up AND tails down. Split it 50/50 and you are done. It is not as easy as to just split it. And it says heads UP tails UP. Given 10 h, 90 t. Pick some random 10 coins call it P1. Rest is P2. In P1, (10-x) heads, (x) tails In P2, (x) heads, (90-x) tails Flip the coins in P1. In P1, (x) heads and (10-x) tails P1 and P2 have the same number of heads. reading these answers is such a confidence builder. Show More Responses I agree to trev, don't think anyone read the question. we already have 2 piles --> 90 coins with tails up and 10 coins with heads up, just flip over 10 of the coins from 90 coins that have tails up, we will have same number of coins with heads up in each pile. get all coins in your hands, shake them, drop them. for each coin there is a 50% probability to lay heads up, and 50% probability for tails down. now split i half question doesn't need to look faces of which side is up after splitting it in two piles. split all coins in two part of 50 50 and they all have heads ...and thats what questioner asking..! and move them to the 10-coin pile. Take 40coins from 90-coin pile, flip them over and move to the 10-coin pile. It's really depends on whether Apple is hiring Software Engineers who are collaborators, mathematicians or tricksters. It's clear that Apple does hire Engineers who listen to the question accurately. Make two groups at random for 10 and 90 coins. Example:- G1(10) G2(90) case 1:- 6H,4T 4H,86T case2:- 3H,7T 7H,83T Now flip all coins of smaller group G1(10). The result will always have same Heads in each pile. G1(10) G2(90) case 1:- 6T,4H 4H,86T case2:- 3T,7H 7H,83T We just get 5 coins head up put in each piles ==> we get the same number of head up in each pile. They just ask we "Split the coins into two piles such that there are the same number of heads in each pile" . They didn't say that we don't kow what is coin head up and they mixed together. "The question says "'You' can't feel, see or in any other way find out which side is up....' Can a team member? Cooperate with a fellow engineer, or other colleague, who can see the coins to solve the problem?" This is the best answer yet! Completely out of the box answer and yet so simple. Show More Responses Flip every other coin, 90 Tails will get split into 45 Heads and 45 Tails. Similarly 10 Heads will get converted to 5 Head and 5 Tails, so now we have 50 heads (45 + 5) and 50 tails (45 + 5). Then just split them into two equal groups. Find complete answer with description here: http://www.puzzlevilla.com/puzzles/puzzle/172 Answer Make a pile of 10 and flip them over. Then the number of heads is equal in both piles. question says both group should have equal heads, but doesnt specifiy, it should be up, hence, just grouping 50 each would solve the problem This is a screw you question, but yeah if you take out 10 coins you can have anywhere between 0-10 heads for every head you have you have one less head in the other pile and one less tail in your pile of 10 coins. So if you have 100 coins 10 heads and you take lets say 10 coins 0 heads, 10 tails. The 90 coins has 10 heads. 1 heads, 9 tails. The 90 coins has 9 heads (you stole one when selecting 10 coins). 2 heads, 8 tails. The 90 coins has 8 heads (same you stole 2 when selecting 10 coins ect). 3 heads, 7 tails. The 90 coins has 7 heads. 4 heads, 6 tails. the 90 coins has 6 heads. 5 heads, 5 tails, the 90 coins has 5 heads. 6 heads, 4 tails, the 90 coins has 4 heads. 7 heads, 3 tails, the 90 coins has 3 heads. 8 heads, 2 tails, the 90 coins has 2 heads. 9 heads, 1 tails, the 90 coins has 1 heads. 10 heads, 0 tails, the 90 coins has 0 heads. As you can see whenever you take out 10 because your not only stealing from the pile of 90's heads your also offsetting the pile of 10 coins tails by 1 equally you have an equal connection between the tails you have in the pile of 10 coins as you do heads in the pile of 90 coins that your tails in 10 coins pile always equals heads in 90 coin pile. So you just flip over each coin in the pile of 10 coins and your tails becomes heads. So if you selected 1 head and in the 10 coins pile you had 9 heads in the 90 coins pile and 9 tails in the 10 coins pile, you are guaranteed after flipping each over once to have 9 heads in the 10 coins pile as tails becomes heads and 9 heads in the 90 coin pile, and ect, ect. This stands true for any pile that you know the amount of one category and 2 options, If you know you have 25 of one things, despite how many things there are if each thing had only two options like heads or tails, you know selecting 25 of them the same amount you know of one thing that when taking out 25 or the equal number of what you know of one thing is in there that what you unsucessfully try to filter out is the inverse of what you selected successfully to take out. Pick 10 coins, flip them and form a separate pile. The no.of tails in both pile will be equal inspite of your choice being a tails up coins or a heads up coins. Coz when u pick a tails up coin u r reducing the no.of tails up in the first pile and since u flip it its gonna b a heads up coin the second pile, if u r picking up a heads up a coin u turn it into a tails up coin in the second pile so that it can cancel out one tails up coin in the existing first pile. If it means heads up then separate the coins into one pile of 90 one pile of 10 then flip the ten coins it works with all scenarios Of sides you ended up choosing also like to point out that we can't feel them so we probably can't use our hands to flip them but I assume they would allow us to use something as how else would we separate them The answer lies in the exact wording of the question "Split the coins into two piles such that there are the same number of heads in each pile. " It does not specify heads need to be face up, so you would simply split the piles in 50 each and you have the same number of coins with heads in each pile. Take ten coins (consider as one pile, Pile A and other 90 coins as another pile, Pile B). Now you have two piles. Turn all coins as in pile A, you will end up with same number of heads in both piles. Ex: Scenario 1: Consider in Pile A, there are 2 heads and 8 tails. Hence in Pile B there will 8 heads.Now when you turn all the coins in Pile A you will end with 8 heads in Pile A. Hence both Pile A and Pile B have same number of heads. Scenario 2: Consider in Pile A, there are 10 heads. Hence in Pile B there will be 0 heads.Now when you turn all the coins in Pile A, you will end with 0 heads in Pile A. Hence both Pile A and Pile B have same number of heads. Scenario 3: Consider in Pile A, there are 0 heads. Hence in Pile B there will be 10 heads.Now when you turn all the coins in Pile A, you will end with 10 heads in Pile A. Hence both Pile A and Pile B have same number of heads. Show More Responses Take 10 coins.Split into two piles of 5 each.Flip all coins in one pile.Both piles now have equal heads and tails.Take another 10 and go through the same procedure.Follow the same process for the entire original pile.You end up with two sets of 5 piles having equal no. of heads and tails.Combine all 5 piles on each side and it's done. Its very simple. step 1 take group of 10 coins from all now flip this pile and you will get your answer. how? lets see cases 100 total ( 10 H + 90T) so you get group of 10 from them so lets assume you will get 4 h+6T , and (6H + 84T) then flip this smaller one new group will be 4T+ 6H so now we 2 groups 1 new 1 old 4t+6h and 6h+85T both have same number of heads .... LITERAL ANGLE Split 50/50. Both piles have the same number of heads. Parameters do not require each pile to have the same number of heads facing upward. TEAMWORK ANGLE Ask the most efficient, skilled coin identification analyst at Apple to identify the coins so the skilled sorting robot can separate the piles equally. PATRONIZING ANGLE Take a picture of the table with your iPhone and sending to a laborer hired to come sort for you via a services app in the app store. NEXT LEVEL QUANTUM ANGLE If the coins are in no way observable, the question is impossible to answer because the coins are sitting next to Schrodinger's cat and thus are in a state of both heads and tails until observed. |

### Software Engineer at Apple was asked...

Find number of ones in an integer. 13 Answers1. Convert the number into bits (we assume that all our bits of size 8) 2. "And" it with 1 3. check if the bit returned is 1 or now. if it is '1' increase some counter. 4. right shift 8 times and perform go to 2 or you can do the following using properties of number. every number when AND'ed with number - 1 it would eliminate one binary number.\ count = 0; while(n) { n &= (n-1); count++; } This doesn't work: 1. Convert the number into bits (we assume that all our bits of size 8) 2. "And" it with 1 3. check if the bit returned is 1 or now. if it is '1' increase some counter. 4. right shift 8 times and perform go to 2 look at the number 11: counter=0; 0x000B, look at the last byte B: 1011 and that with 1, you get 1 counter now equals 1, right shift 8 times and get 0x0000 and with 1, get 0, doesn't increment counter. so the number of 1's in 11 is 1. Show More Responses This doesn't work either: or you can do the following using properties of number. every number when AND'ed with number - 1 it would eliminate one binary number.\ count = 0; while(n) { n &= (n-1); count++; } Look at n=7, which we know has no 1's in it. 7 in binary: 0111 6 in binary: 0110 n=7&6; so n=6; counter=1; loop again: 5 in binary=0101; n=6&5=0110&0101=0100=4; counter=2; We can already see this is wrong answer should be 0; Solutions provided above are used for finding out the number of ones in a binary string. If you Google for such question, both proposed answers would show up. For finding out the number of ones in an integer, I would propose the following. int NumberOfOnes(double number) { int counter = 0; if (number == 0) return 0; if (number == 1) return 1; do { if (number % 10 == 1) counter++; number = number / 10; } while (number); return counter; } Binary ones in python: def findBinOnes(integer): val = integer ones = 0 while val > 0: if val & 1 == 1: ones +=1 val = val >> 1 return ones Decimal ones in python: def findDecOnes(integer): val = integer ones = 0 while val > 0: if val % 10 == 1: ones += 1 val = val / 10 return ones just an idea #!/usr/bin/env ruby 123456718791.to_s.scan(/1/).size int numOfOnes( int n ){ int num = 0; String str = Integer.toString ( n ); for(int i = 0 ; i < str.length() ; i++ ) { if ( str.charAt ( i ) == '1' ) num++; } return num; } In Perl: sub OnesInNum{ my $number = shift; my $count; my @numbers = split //, $number; foreach my $num (@numbers){ next if($num eq '.'); #skip decimal point $count++ if($num == 1); } return $count; } #include #include using namespace std; int CountBits(const int& number){ int test = 1; int count = 0; for (int i = 0; i < (sizeof(number)*8) ; i++){ int filter = number & test; if(filter) count++; test <<= 1; } return count; } int _tmain(int argc, _TCHAR* argv[]){ cout << CountBits(566632145) << endl; return 0; } Convert to binary and iterate. Check last big (increment counter if 1) then bit shift right to drop last bit. repeat. int main(void) { int input, counter = 0; printf("Enter integer: "); scanf("%d", &input); while(input) { if ((input & 0x0001) == 1) {counter++;} input = input >> 1; } printf("No. of 1s are: %d", counter); } Perl read fm stidn: chomp ( my $int = ); my $ones = $int =~ tr/1/1/; say $ones; |

What is the funniest thing that has happened to you recently? 14 AnswersThe idea that this interview question has anything to do with hiring the best employees for a restaurant chain. Sitting before you & pondering over this question........ Sitting before you & pondering over this question........ Show More Responses When applying for a pizza delivery person, one question was how I could benefit from scissors. congress... Rob Ford I was laid off when my function was eliminated. The funny joke is on the former employer who has already lost >10M in sales that were 'in the bag' because no engineer was there to support the products through development to market. Actually, that's not funny at all, but it is what happens when disconnected finance office chair-warmers dictate budgets instead of Sales VPs. I went to a job interview at Appelbee's. I went to a job interview at Applebee's. Funny you should ask that... I just got a text from Friday's saying I got the job I was interviewing for last week - with double the amount of pay I was asking for. Would you like to try and beat their offer ? I won Bartender of the Year at a Friday's... good time, good time.... Nothing very unusual happens to me, everything is predictably possible out of the myriad labyrinth of possibilities Accepted works as a manager at a construction company with experience as a dishwasher Show More Responses Recently? Reading all the Glassdoor answers referring to being a pizza guy with scissors. |

### Senior Software Engineer at Apple was asked...

In a stream of integers from 1 to n, only one number will be repeated. How can you tell what that number is? 11 AnswersThis felt like a brain teaser question to me, and since I hadn't heard it before it took me a little while to come up with a solution that involved using a factorial function. You know n. S = n*(n+1)/2 is the sum of 1st n numbers. P = sum of the n+1 numbers you are provided with. Finding P given an array of n+1 integers can be done in O(n). P - S is the repeated integer. Heres an explanation, http://www.techinterview.org/post/526329049/sum-it-up Show More Responses int sum = 0; int xorSum = 0; for(int i =0 ; i < n; i++) { sum += input[i]; xorSum ^= input[i] } return (sum - xorSum)/2; Mat, try 1,2,2,3: 1+2+2+3= 8 1^2^2^3= 2 (8-2)/2=3?2 A hash table would resolve the question with O(n) Add to HashSet. It will return true if it exists. If you're writing it in ruby def find_repeat(numbers) numbers.length.times{|n| return numbers[n] if numbers[n] != n } end lmao, ok everyone getting a little craycray, why not just simply this.... int prev << stream; while (stream) { int curr << stream; if curr == prev return else prev = curr; } (sum_of_numbers - (n*(n-1)/2)) Add each integer to the map if it doesn’t already exist as key if it’s exists then it is a repeated number. |

### Inventory Specialist at Apple was asked...

What was the hardest thing you ever had to do in your prior work experience? 7 AnswersLeave Climb out on a ledge in order to weld a beam no harness 50 feet up, nothing to hold onto once my welding helmet goes down and i lean over. I got out there and couldn't make myself let go. I was walking on a 3" wide beam. I failed. my scared ass had to get another idiot to do it. lol I worked in starting based organisation. There were v.less seniors. So, if there is any issue, I alone did R&D and resolved it. Though, I took time to resolved, but that made me aware of many scenerios and gave confident boost. Show More Responses Travel to Hawaii to fire a rep. It was bad because there was no time to stay and relax. The owner insisted that I return immediately! Had to terminate a female employee who was badly injured from a fire. It had been proven via testimony to us that she covered herself with gasoline and lit it off to get even with a boyfriend, but she said it was due to an accidental kitchen fire. Fire Marshall report also verified she was not telling truth. Our policy said no coverage from 'self-inflicted' incidents and she had lied to us about the cause of the fire. As I told her she was being terminated, I was looking at a melted face, and compresses on each of her arms, and in a torso cast. This was three months post incident and investigation. You don't feel good after a day like that one! This is a comment. Steve... wow. THAT'S not hard... that's unreal. The hardest thing I had to do is doing something for others |

### Ios Software Engineer at Apple was asked...

If you have a program that runs slow, how will you improve it to run faster? 7 AnswersI suggested to check how memory was allocated (if it leaked some) and what operations consumed more CPU cycles and perform some operations in a background thread, keeping the UI update in the main one in order to give UI responsiveness. It depends on the application. Is it CPU-bound or I/O-bound? 1. Check all I/O that the application does: look at I/O speeds, blocking vs. non-blocking calls, see how much time CPU is waiting on I/O using iostat. 2. If I/O is ok, look at CPU usage. Profile the application: look at function call timings, see if any function call is taking abnormally long. Look at garbage collection that may be more frequent if program is using a lot of memory, perhaps due to a memory leak. Calculate the comlpexity and findout what unit of code taking too much time. Make the strategy and improve the code complexity on that. If you are done with that. Go over memory management and find the way to improve it. Also try to make multithreading or pre data process management steps if needed. Show More Responses First thing to approach this problem will be to perform code optimization. There are five steps in which this can be done to increase overall efficiency of the program. 1. Compile time evaluation. 2. Elimination of sub expressions. 3. Dead code elimination 4. Frequency reductions 5. Strength reductions. If you have done all the above steps and still the performance has not improved as expected, then you can see the memory usage 1. look for memory leaks by performing an operation in the application and record memory usage and memory free after operation is done, so that you will be one step closer to the offending operations. 2. Check if launching the applications causes huge amount of memory to be allocated from heap, that will cause the OS to run slower, since it will try and allocate resources by taking resources from other applications which will cause other applications to ask for resources, so the system at this point will be in loop which could be one of the reasons why the system is slow. @Vishal, I've always heard the first rule of performance optimization is don't - until you're absolutely sure what needs to change. Randomly changing code/guessing is a great way to waste time and possibly make things worse, or not find any gains. Profile, analyze, figure out where the time is spent before touching any code! TI's response is the best one I think. I don't know Couple of things to double check: - removing Unreferenced or dead code from executable file. This can be done some using Xcode settings. - eliminate memory leaks: can be checked using instruments. - use SQLite or codedata instead of manipulating data from flat files. - use Xcode compiler level optimization’s for the final release build. - don’t block the main thread, instead use GCD to run potential big operations in background thread. - minimize global variables, instead use run time Malloc allocated block of memory. |

### Software Engineer at Apple was asked...

The unexpected question was about reversing a singly linked list with the given prototype. But I was the one to be blamed as I wasn't well prepared. 7 AnswersIt took me sometime to write this out as I haven't done this in a long time at my current job. You can always loop through the list and push each element on a stack. Once you finish looping, clear the list, and start adding the elements back off the stack. Usually, they requires IN-PLACE Show More Responses If you can use extra space, you could traverse, make a vector of all the nodes, and then rebuild in the opposite order with another traversal. The best answer is definitely non-recursive, and not using a stack. Using a stack works, but it's a waste of memory.. Pretty simple if you think about it. Start with three node pointers: PrevNode=NULL, CurrentNode=head, and NextNode=head->next. Now, loop until NextNode==NULL, and each time: set CurrentNode->next = PrevNode set PrevNode = CurrentNode set CurrentNode = NextNode set NextNode = CurrentNode->next This will swap the connections of every node. Afterwards, just swap the head and tail pointers. If obj is the linked list object supplied. def ReverseLinkedList(obj): new_head = None while obj: obj.next, obj, new_head = new_head, obj.next, obj return new_head y = ReverseLinkedList(obj) #Reversed linked list |

### Senior Software Engineer at Apple was asked...

Print out, from small to big, of a sequence intergers, without sorting. 6 Answerspriority queue then The problem refers to dynamic programming, Longest increasing sequence in the given array. The time complexity of solution is o(n2). Add the sequence of integers to HashSet, which will apply natural order and then print the collection elements. Show More Responses If the integers are within a small range, then create an vector array, loop through all integers and flag the array. Then print out. Construct binary search tree and do inorder traversal. Use a visited array. Run n passes on the given array picking smallest integer every time that has not been visited yet |

### Build Engineer at Apple was asked...

Are you smart? 7 AnswersYes, at-least by the standards of the people I worked and studied with in the past. i'm f**** smart http://en.wikipedia.org/wiki/Dunning-Kruger_effect The results of the Dunning-Kruger study show that incompetent people massively overestimate their ability, while truly competent people are typically unaware that they are on the far-right side of the bell curve. Assuming that the interviewer is aware of this effect, the best strategy to play is modesty. Show More Responses http://www.newscientist.com/article/mg20227115.500-humans-prefer-cockiness-to-expertise.html On the other hand, people prefer cockiness to competency, so maybe the best answer is to boast about how you taught Donald Knuth everything he knows. i am delicate balance of confidence and humility, lets put it that way It depends on how do you definition and measure smart? In looking at my employment history and referencing my level of education along with my accomplishments, I'm confident I've meet your prerequisites and exceptions for this job. I am smart enough to know that there's always more to be learned. Smart is a relative term. But I’d like to think I’m good at solving problems other people are afraid to take. |