# Engineering Interview Questions in Los Angeles, CA

Engineering interview questions shared by candidates

## Top Interview Questions

You are in a boat in a pool with a rock in your hand. You throw the rock into the pool. Does the water level rise, drop, or stay the same? 12 Answersdepends on how big the pool is and how accurately you can measure the water rise you're already in the pool with the rock, so the water displaced is the same...this other guy is stupid If the rock were neutrally buoyant the water level would remain the same. It is heavier than water which causes it to displace more than its own volume while in the boat compared to at the bottom of the lake. Therefore the water level of the lake would go down. Show More Responses At the moment the rock leaves your hand the water falls in the pool. When the rock enters the water the water level of the pool rises again to the level it had before you threw it. really? I thought the water would go up ? These answers are troubling. The only correct answer so far is Ben. The water level goes down. I'm not a mechanical engineer, but I did stay in a Holiday Inn Express last night. I hope no one else who has answered this question here (except for Homebrook) is a mechanical engineer. When you add the volume of the rock and subtract the volume of water previously displaced by the boat+rock, there is no change in the water level of the pool. Another way to answer is: The water level measured at the side of the pool remains the same. The boat becomes more buoyant and the water level measured at the side of boat falls. The weight of the boat plus you plus the rock has already displaced the height of the water. The only time the water level will change will be when the rock is mid air. M no Bbbbbbbbbbbbbbbbbbvvbvbbvbbb. B.B. BNb. Bbbb Bbvbbbbbbb Bbbbbbbbb B.B. Bbbbb V bbbb BNb B.B. BNb Bbbbbb BNb BNb Bbbb. BNb B b. Bbbbbbbb. N n. Bbbb. B B.B. N BNb bbb Nnnnn Nnnn nnn Nnnn Nn N. Nn N M Mm. I. N. M M m Mmm n nnn Mmm mmnmmmnm Mmnmmmmm Mmm my Mmmm Mmm Mmm Mmmmmmmmm m Mmmmmmmm It will raise by the same volume of the rock. First time, the water buoyant force is equal to the mass(boat + person + rock).g /subsequently, the water got displaced was also that much, the water level on the pool will be higher. second time, since rock is gonna deposit down to the bottom of the pool, it'll be like: water displacement = (boat + person).g + the volume of the rock (but it's probably much less than the water displacement it could have created when it's on the boat). There is no way that rock is displacing the same amount of water as it did previously. (1kg gold (Density: 19.30 g/cm3) and 1kg silver(Density: 10.49 g/cm3) in normal situation has different volume, so when deposited to the bottom, silver will displace more water than gold, yet both displace less water than when rock was sun-bathing on the boat) In conclusion, first time the water level was higher both on the pool wall and the mark on the boat, second time it'll be lower on both end. Depends on how big the rock is |

What has been your active role in the team process you're currently working with? 2 AnswersExplained details of daily involvement, software used, level of completion of initial input received, and final deliverable. I quote the repairs and write up the job router steps to include R & R parts, inspection. Testing, and FAA 8130 |

A penguin walks through that door right now wearing a sombrero. What does he say and why is he here? 84 AnswersI was obviously thrown off by the question and felt it was irrelevant. I answered with, "Where's the sun screen?" Complaining about global warming.?! Here's a useful answer: The use of the term Sombrero implies a particular ethnicity or nationality therefore to answer the question might violate HR compliance with federal and state law. Show More Responses He wouldn't say anything. He is a penguin. Probably there because he's a party favor that got loose and waddled in. It is also awesome. @PK - not necessarily. Did you ever witness a deboarding of a plane from Cancun or any other vacation destination during spring break? There are quite a few college kids, who I'm sure continued their party on the plane, getting off wearing those gaudy souvenir sombreros. You would actually implicate yourself by assuming that. Did your secretary slip something into my coffee? i guess I dont speak penguin to really understand what it said. "Am I South of the Border yet?" The penguin was obviously travelling back home to the South Pole and, thinking he already reached Mexico, wore the sombrero to blend in. He's a Linux consultant (either Mexican or returning from a Mexican vacation) and is going to ask for directions and access to the server rooms so he can get to work. Necesito un poco de hielo por favor Hi, my name is Tux and I'm here to take over your IT department. I live in New York, so I probably wouldn't see any issue here. Buenos Dios amigos. Do you have any ice? Show More Responses The penguin says "Stop asking stupid interview questions" "Those seals really know how to party!" He says: Most people will not answer both questions. And he is here because you brought him with your imagination, please take him back to his home and lets start the real interview. I'll be back :-) Salsa really doesn't go well with herring. He asked "is it 5'oclock yet?". He is here because he's the company's mascot and has been specially trained to make frozen margaritas in the walk-in freezer. "Perdone, ¿dónde está el baño?" I assume he is there to steal my Bud Ice, and probably is singing "Do-be do-be do". The sombrero is irrelevant. He says, "I'm here to do the cha cha, and I'm here to take your money." If a fantasy-type question is asked, I'm allowed a fantasy-type answer, correct? Business on bottom (tux) and all party on top. Show More Responses I would ask the interviewer: "An African or European penguin?" "Got Ice" "Hola!" He is a lost and stranded sound engineer for a Def Leppard reunion tour looking for an inexpensive Sony multichannel digital tape recorder. "Hola!" He is a lost and stranded sound engineer for a Def Leppard reunion tour looking for an inexpensive Sony multichannel digital tape recorder. "Excuse me — I was told the dress was business casual. Anyway, I'm here to tell you about the great benefits package we offer." I need help. Please take this sombrero out of my head and recycle it. So, you don't do drug testing here, huh? "Trick or Treat" Location must be at the tip of Argentina or Chile, unless the penguin got stuck on a floating iceberg in which case he could be coming ashore nearly anyplace. Theoretically. Penguins don't talk, but his or her body language communicates confidence in this company. I'd guess the costumed penguin is here for some promotion... speaking of promotions... Show More Responses He would ask "Wha-a-at a-are yo-o-u smo-o-oking?" ;) it's me the thing you have feared all your life... this is not a dream I am real How is my outfit ? In the 3rd answer, PK indicated that " the question might violate HR compliance with federal and state law." I don't know about that, but it got me thinking about the motivation for the question - and here's my guess. It is quite possible that they are asking the question to find out if you might stereotype Mexicans - and stereotyping probably means that you are prejudiced - which in turn - means that you will not likely work well on a construction job site. "I knew I should have made that left turn at Albequerque!" He's obviously flown in from Mexico for the job interview. "I hear you are an equal opportunity employer?" he says delightedly, "I'm not so good with heights but I make wonderful margueritas" Penguin: "Holy crap! Vegas is amazing! Hookers, gambling, drinking games AND job interviews!" If the penguin is walking into the room where the interview is taking place one could assume he was the CEO if he has the audacity to wear a sombrero. Therefore, I imagine he would say upon seeing my smiling face, "Hire this man immediately and double - no, triple his salary! Well, this the last time I'll use the Apple Maps program . . . There is an upside even in global warming: margaritas y chiquitas. Hola! Show More Responses What does he say? "does this suit make my hat look too big?" Why is he here? "he desired some constructive criticism" Buenos dias. I need to build an Igloo. Am I in the right place? He (the penguin) indicates that I've fallen asleep and I'm having a strange dream in which I'm being asked stupid interview questions by a pretentious HR person who is trying to look clever. Clark Construction can you build me an insulated igloo with air conditioning. I just moved to Mexico and it is too damned hot. Having put 12 years in a Catholic School, I was surrounded by Penguin's on a daily basis. Our Spanish teacher was the only one who would have worn a sombrero, but I don't think that she was a he/she. Classmate Sue, on the other hand, could get me to salute on a daily basis. If she walked in wearing a sombrero and holding a pinata, I would salute that too. Humor and Reality. Feed the interviewer something like this, and you could be a Supervisor. Just say it with a straight face. oops, i entered into a wrong room. you can carry on. Good evening, I am here to keep forward with the interview, are you ready? By the way you will need a sombrero. penguin said that outside temperatures are high and so that he was here in the room which had air condition. Penguin says: The Batman is annoying *Batman saves the world from being penguin-ated* "You know, if you wanted your candidate to wear a tux, there are far cheaper ways of getting the point across." Show More Responses Adios! See you next week when I'm back from vacation in Mexico. "i quit" Does it really matters?????? Whatever the penguin says, we are not going to understand a bit. "Kill me" penguin doesnt speak You're hired. penguin wants to be the first to congratulate me on my selection "Is this club pinguin ? how do I get back".... clubpenguin.com I don't friggin care what the penguin says. I just found a talking penguin. I'm rich! "Someone here drank WAY too much last night" Show More Responses oh, sorry to bother you, do you know where i can find the mexican themed black-tie event that's going on somewhere around here? The penguin says: "Hey, have any of you guys seen my brother?" Then I say: "I don't know - what's he look like?" "Hola, soy Nieves. Necesito regresar al Polo Sur. Puedes ayudame?" Do you have the time? I think I'm late for my movie. QUE PASA AMIGO You're hired I may look different to you but I am 100% capable of completing my job duties. Sorry, I told him to wait in the van. "Where the tequila?" - he's obviously on vacation! Penguins can't speak in a language I can understand. But if it could speak english, the penguin would probably say "That was one hell of a party the HR department had last night, am I late?" Show More Responses Just to waddle in and show off his new hat The penguin would say "don't be afraid that I can walk through doors. Here, put this sombrero on. You're hired." I am not aware yet of why he's here . He has not told me yet.He says "hello" and I say "hello madamoiselle". He's your power animal, you brought him here. He only said one word..."slide!" He's fight clubbing himself...we got a fight clubber! I had a silly woman asked me during an interview who is my favorite super hero and why... I wanted to answer her question truthfully and get up and leave. What a moran? No brain. Have you accepted the Lord Jesus into your heart? "You are hired, and no more questions for the day" Hi, dudes! You have drunk a lot of kefir yesterday. (a voice could be bass) Sharp healthcare "Where's my fish taco?" Show More Responses “It’s too damn hot for a penguin to be just walking around” |

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

you have a sequence where each number is a multiple of 2 or 5 (so: 2^i * 5^j). he gave the beginning of the sequence as 1,2,3,4,5,8,10,16... and asked me to find an algorithm to calculate the next number in the sequence. 20 Answersbefore i post the answer, i'm curious if anyone here could explain the approach that you should use. i didn't understand how the sequence worked. How is 3 (the third number in the sequence) equal to 2^i * 5^j? Is 3 supposed to be there, or is it a typo? Good catch! Sorry about the typo. I'll write a little more too: The start of the sequence is 1,2,4,5,8,10,16, 20, 25, 32... Any thoughts? Show More Responses There are two sets: - Set-I is powers of 2 {2, 4, 8, 16, 32, 64....} Set-II is powers of 5 {5, 25, 125....} Set-III is composite function of both the above set {10, 20, 40,50, 80.......} Now start with Set-I and keep on displaying it until it is less than 1st element of Set-II ans Set-III or otherwise display an element of Set-II or Set-III which ever is less. Note:- Set-III is formed by multiplying Set I and Set II in sorted manner. (A code snippet is required to generate it) There are two sets: - Set-I is powers of 2 {2, 4, 8, 16, 32, 64....} Set-II is powers of 5 {5, 25, 125....} Set-III is composite function of both the above set {10, 20, 40,50, 80.......} Now start with Set-I and keep on displaying it until it is less than 1st element of Set-II ans Set-III or otherwise display an element of Set-II or Set-III which ever is less. Note:- Set-III is formed by multiplying Set I and Set II in sorted manner. (A code snippet is required to generate it) There are two sets: - Set-I is powers of 2 {2, 4, 8, 16, 32, 64....} Set-II is powers of 5 {5, 25, 125....} Set-III is composite function of both the above set {10, 20, 40,50, 80.......} Now start with Set-I and keep on displaying it until it is less than 1st element of Set-II ans Set-III or otherwise display an element of Set-II or Set-III which ever is less. Note:- Set-III is formed by multiplying Set I and Set II in sorted manner. (A code snippet is required to generate it) I would also take the approach from An Idiot. What was the answer given by the interviewer? public class googleAnswer { public static void main(String args[]){ int[] sequence={1,2,4,5,8,10,16, 20, 25, 32}; System.out.println(getNextNumber(sequence)); } public static int getNextNumber(int[]sequence){ int curNum=sequence[sequence.length-1]; System.out.println(curNum); boolean found=false; while(!found){ curNum++; int tempNum=curNum; while(tempNum%5==0){ tempNum=tempNum/5; } while(tempNum%2==0){ tempNum=tempNum/2; } if(tempNum==1){ found=true; } } return curNum; } } The interviewer said something like multiply each number by 2 and also by 5 (two separate operations). This would give you: 1 x 2 = 2 1 x 5 = 5 then look at the smallest unused number and use that for the next set of operations: 2 x 2 = 4 2 x 5 = 10 and so on ... I like the way of thinking about it as three sets better. Too bad I didn't think of that during the interview! I was hung up looking for a pattern in the exponents since he phrased it as 2^i * 5^j. It seemed like there was one until he gave me sample values after 20. This question really threw me off because it's not like the other google interview questions I read about. It would have been interesting to pursue it past the math sequence portion (merging sets of streams of numbers). Thanks for the feedback, though! At a second glance, the sequence is surprisingly simple. It is merely the set of all numbers 2^i * 5^j in ascending order (where i, j >= 0). The above answer can be implemented by a stack sorted in ascending order. Start off with 1, multiply it by 2 and 5, and put the products in the stack. Then go through each element in the stack, multiplying it by 2 and 5 and putting the products in the stack. (However, you don't want to insert duplicate entries, so you'd need to check for that while inserting the entries, but that wouldn't reduce the space/time efficiency.) Anyone with more efficient solutions? Here's an easy python solution. it doesn't print the first element in the sequence (1): #!/usr/bin/env python from operator import itemgetter a = 2 b = 5 x = 0 y = 0 ptr1 = 2 ptr2 = 5 for i in range(30): h = { a**(x+1) * b**y : (lambda x,y,ptr1,ptr2: [x+1,y,ptr1,ptr2]), a**x * b**(y+1) : (lambda x,y,ptr1,ptr2: [x,y+1,ptr1,ptr2]), a * ptr1 * ptr2 : (lambda x,y,ptr1,ptr2: [x,y,ptr1*a,ptr2]), ptr1 * b * ptr2 : (lambda x,y,ptr1,ptr2: [x,y,ptr1,ptr2*b]) } for k, v in sorted(h.iteritems(), key=itemgetter(0), cmp=lambda i, j: i - j): if k > 0: print k x,y,ptr1,ptr2 = v(x,y,ptr1,ptr2) break Slight modification to my solution to fix an off-by-one error #!/usr/bin/env python from operator import itemgetter a = 2 b = 5 x = 0 y = 0 ptr1 = 2 ptr2 = 5 last = 1 for i in range(30): h = { a**(x+1) * b**y : (lambda x,y,ptr1,ptr2: [x+1,y,ptr1,ptr2]), a**x * b**(y+1) : (lambda x,y,ptr1,ptr2: [x,y+1,ptr1,ptr2]), ptr1 * ptr2 : (lambda x,y,ptr1,ptr2: [x,y,ptr1,ptr2]), a * ptr1 * ptr2 : (lambda x,y,ptr1,ptr2: [x,y,ptr1*a,ptr2]), ptr1 * b * ptr2 : (lambda x,y,ptr1,ptr2: [x,y,ptr1,ptr2*b]) } for k, v in sorted(h.iteritems(), key=itemgetter(0), cmp=lambda i, j: i - j): if k > last: print last x,y,ptr1,ptr2 = v(x,y,ptr1,ptr2) last = k break Well, we can make several observation: * a number multiplied by 8 (2^3) is always larger than that multiplied by 5. * if we seed the list with 2 consecutive multiple of 2 (e.g. 2 and 4), we do not need to multiply the number by 2 (2*2 = 4 is already in the list) and only need to multiply by 4 (see that 2*4 = 8, then 4*2 = 8, oops already in the list) * if we have a number that is divisible by 5, we simply need to multiply it by 5 since the results of multiplying the number by 2 or 4 would have been generated previously (we note that 5n * 4 is equivalent to 4n * 5, obviously 4n < 5n; similar argument for multiplication by 2). Hence, here is a very simple algorithms to generate the first n numbers in the sequence: 1. we start with a seed of [1, 2] 2. we iterate through the list until length of list = n, for each number k we see, (a) if k is divisible by 5, append to the list 5k, otherwise (b) append 4k and 5k def createPowerList(n): lst = [1, 2]; i = 0 while len(lst) < n: currentValue = lst[i] if currentValue % 5 == 0: lst.append(currentValue * 5) else: lst.append(currentValue * 4) lst.append(currentValue * 5) i = i + 1 return lst Show More Responses Forget that. It makes a small mistake. Instead this simpler version would work much better. :) def createPowerList2(n): lst = [1] power_of_2 = 2 multiply_by_5 = 0 while len(lst) < n: if power_of_2 < (lst[multiply_by_5] * 5): lst.append(power_of_2) power_of_2 *= 2 else: lst.append(lst[multiply_by_5] * 5) multiply_by_5 += 1 return lst This is in groovy. print out sequences to 1000 int[] seq = new int[10000] int p2 =0 int p5 =0 seq[0] = 1 index=0 while (seq[index] v5) { seq[++index] = v5 p5++ } else { seq[++index] = v2 p2++ p5++ } }// while( for(int j=0; j<=index; j++) { print(seq[j] + " ") } C++ implementation of the algorithm described in CTCI #include #include using namespace std; void printMultiplesOfTwoAndFive(int n) { deque two; deque five; two.push_back(1); five.push_back(1); while(n != 0) { auto v2 = two.front() * 2; auto v5 = five.front() * 5; if( v2 v5) { cout << v5 << endl; five.pop_front(); five.push_back(v5); two.push_back(v5); } else { cout << v5 << endl; five.pop_front(); two.pop_front(); five.push_back(v5); two.push_back(v5); } n--; } } int main() { printMultiplesOfTwoAndFive(100); return 0; } int GenerateNewNumber(int curInd) { queue f,s; int val; f.push(1); s.push(1); for(int i = 0; i < curInd; i++) { val = min(f.front(), s.front()); if(f.front() == val) { val = f.front(); f.pop(); } if(s.front() == val) { val = s.front(); s.pop(); } cout << val << " "; f.push(val * 2); s.push(val * 5); } return val; } int GenerateNewNumber(int curInd) { queue f,s; int val; f.push(1); s.push(1); for(int i = 0; i < curInd; i++) { val = min(f.front(), s.front()); if(f.front() == val) { val = f.front(); f.pop(); } if(s.front() == val) { val = s.front(); s.pop(); } cout << val << " "; f.push(val * 2); s.push(val * 5); } return val; } 40 Enumerable.Range(0, MAXN). SelectMany(x => Enumerable.Range(0, MAXN). Select(y => Math.Pow(2, x) * Math.Pow(5, y))). OrderBy(x => x); |

Write a function that finds the median of a set of three numbers, also find the Big O. Can it be done with only 2 comparisons, or do you need 3? 11 AnswersPick two numbers: A and B, Add the third number to each of the first two : (A+C), (B+C). Compare these two numbers and take the lesser of the two. Now compare C with the other member of the less number. The greater of these two is the median. I'm not following. Is this: say, B+C is less than A+C, then the larger of B and C is the median? If so, isn't this a counterexample: A = 2, B = 1, C = 3? Actually the answer is the next one: we could have an answer using only two comparisons. The main idea is that we need to examine one of the numbers to get into the segment created by the other two numbers. And another important thing is that one comparison could be used to definitely determine for both two segments created by two numbers. For example we are trying to examine number A and we have two segments formed by B and C numbers: [B; C] and [C; B]. But considering that for determining if A is in the segment created by B an C we need to make the following comparison: (A - B) * (C - A) >= 0. It is easy to notice that if A is in segment [B; C] (B is less or equals to C) we have both multipliers are positive but in an opposite case when A is in segment [C; B] (C is less or equals to B) we have both that multipliers are negative. If former comparison is negative - then number A is not in any of segments [B; C] or [C; B]. And here is a code of function on C/C++: int medianOfThreeNums(int A, int B, int C){ if ((A - B) * (C - A) >= 0) { return A; } else if ((B - A) * (C - B) >= 0) { return B; } else { return C; } } Show More Responses if (B-A) > 0 if (C-B) then B else C else if (C-A) > 0 then A else C a=b=c ? First get two numbers: x = a - b y = a - c now there are four possible cases for x and y if x & y are both positive => a is bigger than both b and c.=> choose bigger of b & c if x & y are both negative => a is smaller than b and c => choose smaller of b & c if x is positive and y is negative => a is bigger than b but smaller than c => choose a if x is negative and y is positive => a is smaller than b but bigger than c => choose a void GetMedian(int a, int b, int c) { int small, large; if (a < b) { small = a; large = b;} else {small = b; large = a;} // Check where c lies: if (large < c) return large; else if (c < small) return small; else return c; } @Moy: if the answer turns out to be small, then haven't you done 3 compares? Running Vitalii's code with a = 1, b = 7, and c = 3 produces a median == 7, which is incorrect. Suggestions? Vitalii's solution works for me. def find_median(a, b, c): ab = b - a bc = c - b if -ab * (ab + bc) >= 0: return a if ab * bc >= 0: return b return c can't you sort the 3 numbers, the median is the middle one...? |

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

Phone interview question: Given a string pattern of 0s, 1s, and ?s (wildcards), generate all 0-1 strings that match this pattern. e.g. 1?00?101 -> [10000101, 10001101, 11000101, 11001101]. You can generate the strings in any order that suits you. 13 Answerspublic static void generateAllPatterns(String s, int index) { while(index < s.length() && s.charAt(index) != '?') index++; if(index == s.length()) { System.out.println(s); return; } StringBuilder s1 = new StringBuilder(s); s1.setCharAt(index, '0'); generateAllPatterns(s1.toString(),index); s1.setCharAt(index, '1'); generateAllPatterns(s1.toString(),index); } public static void generateAllPatterns(String s) { generateAllPatterns(s,0); } {{{ public static ArrayList getAllString(String str) { if(str==null) return null; int index = str.indexOf('?'); ArrayList res = new ArrayList(); if (index == -1){ res.add(str); return res; } char ch1[] = str.toCharArray(); char ch2[] = str.toCharArray(); ch1[index] = '0'; ch2[index] = '1'; res.addAll(getAllString(new String(ch1))); res.addAll(getAllString(new String(ch2))); return res; } }}} #include #include void findBinPattern(char *data, int i) { if (data[i] == '\0') { printf("%s\n",data); return; } if (data[i] == '?') { data[i] = '0'; findBinPattern(data, i + 1); data[i] = '1'; findBinPattern(data, i + 1); } else findBinPattern(data,i+1); } int main(void) { char data[] = "?1"; findBinPattern(data,0); return EXIT_SUCCESS; } Show More Responses Here's a verbose non-recursive solution that can be traded for some of the solutions above (always think about a bad input like ??????????????????) public void generatePatterns(String str) { // Let's assume an incoming input of 1101?0010?1111? // This means we will have 2^3 = 8 combinations // Let's sweep through the input once and identify the number of wildcards // Once you have the number of wildcards you can generate the permutations Ex: 3 wildcards, clearly my list is 000, 001, 010, 011 etc int ctr = 0; for(int i=0; i permList = getPermutations(ctr); ArrayList patterns = new ArrayList(); for (int x = 0; x getPermutations(int ctr) { ArrayList perms = new ArrayList(); String perm = null; int totalPerms = (2 << (ctr - 1)); for(int i =0; i I like my recursive version the best. public static Set allSets = new TreeSet(); public static Set getAllCombos(String str){ if(str == null){ // Error Check return null; }else if(!str.contains("?")){ // Base Case allSets.add(str); return allSets; }else{ getAllCombos(str.replaceFirst("\\?", "0")); getAllCombos(str.replaceFirst("\\?", "1")); } return allSets; } public static void PossibleStrings(String str) { if (str == null) return; else if (str.Contains("?")) { int findex = str.IndexOf("?"); str = str.Remove(findex, 1); PossibleStrings(str.Insert(findex, "1")); PossibleStrings(str.Insert(findex, "0")); } else Console.WriteLine(str); } Dynamic Programming. Create an arraylist that will store intermediate results. Start from end of string. If a 0/1 is encountered, simply append the character in the beginning to all the elements in result array. If a wildcard is encountered, add both 0 and 1 to all the elements.This pass will double the number of elements on the arraylist. Repeat till the first element is reached. Output the result. Well, things are usually easier in python :) def print_wild_string(s,pos): if pos == len(s): print s return if s[pos]=='?': new_str_0 = s[0:pos] + '0' + s[pos+1:] print_wild_string(new_str_0,pos+1) new_str_1 = s[0:pos] + '1' + s[pos+1:] print_wild_string(new_str_1,pos+1) else: print_wild_string(s,pos+1) An even shorter / cleaner python version: def replaceWildcards(str): if str.find("?") < 0: print str else: replaceWildcards(str.replace("?", "0", 1)) replaceWildcards(str.replace("?", "1", 1)) (full disclosure: I did a few tests with the timeit library and the previous python solution is 20% faster than this one, so if time is your major concern, go with the other python solution. Actually, that solution but replacing the "+" for string concats with "".join() format was 5% faster than the original above if you really wanted to optimize.) void Gen(String pattern){ int n = pattern.length() - pattern.replace("?", "").length(); int[] locs = new int[n]; int count=0; for(int i=0;i C# version: public static void GenerateAllPatterns(string input) { if(string.IsNullOrEmpty(input)) { return; } int index = input.IndexOf('?'); if(index > -1) { // From the input string, create two new strings // which have the ? converted to both a 0 and a 1. char[] c1 = input.ToCharArray(); c1[index] = '0'; char[] c2 = input.ToCharArray(); c2[index] = '1'; // Recursively call this function on the two new strings. GenerateAllPatterns(new string(c1)); GenerateAllPatterns(new string(c2)); } else { Console.WriteLine(input); } } void printChars(string s, string soFar) { if(s.size() == 0) { cout< Scala solution: def generateCombinations(s: String, currentCombination: String, combinations: List[String]): List[String] = { s match { case "" => List(currentCombination) case str if str.head == '?' => generateCombinations(str.tail, currentCombination + '0', combinations) ::: generateCombinations(str.tail, currentCombination + '1', combinations) case str => generateCombinations(str.tail, currentCombination + str.head, combinations) } } def generateStrings(s: String): List[String] = generateCombinations(s, "", List.empty) |

### Software Engineer Intern at Hulu was asked...

Write a power function power(a , b) returns a^b 8 Answersint power (double a, int b) { for (int i = 1, i <= b, i++) { a *= a; } return a; } There are some conditions you are missing. What if b is <=0 ? The conditions made by the Hulu rep was to assume b > 0. However there is a better way to do this problem. Show More Responses long power(int a, int n) { if(n%2==0) return power(a,n/2)*power(a,n/2); else if (n%2==1&&n!=1) return power(a,n-1)*a; else //n==1 return a; } double power(int a, int n){ double res=1; while(n!=0){ if((n&1)==1) { if(n>0) res*=a; else res/=a; } a*=a; n /=2; } return res; } def power(a,b): if b is 1: return a return a * (power(a, b--)) double pow(int a,int b) { if(b0) { if(b%2==1) res*=a; a*=a; b>>1; } return res } def power(a, b): return a**b |

### Test Engineer at Broadcom was asked...

Given Vcc and 2 capacitors A and B in series to ground, what is the voltage in between 4 AnswersSomewhere in between Vb=(Cb/Ca+Cb)V I mean Vb=(Cb/(Ca+Cb))V Show More Responses It depends on the initial condition.... if both capacitors were discharged to 0V at first, and then one side is charged to Vcc, then the answer would be Vb=(Ca/(Ca+Cb))Vcc Vcc---Ca----Cb----gnd However since there was no initial conditions given , the middle voltage could be anything if the capacitors are ideal |

If you had a savings account with $1, at a 100% interest rate, at what year would you have 15 billion dollars? 4 AnswersUse the power of 2's to get to the answer. Log base 2 of 15 billion You should know offhand that 2^10 is 1024, so 2^20 = 1024^2 is approx a million, 2^30 is approx a billion, then you need four more years to get to 16 billion. Remember that you started with 1, not 2, so the answer is 35 years, not 34. Show More Responses After 34 years you would have 16 billion. That is to say, you would have 15 billion in the 34th year. |

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

Give 2 coding solutions on returning an array by removing duplicates. One solution with O(n^2) and the other Linear. 4 AnswersCreate a new array. Run through the original array, on each element insert to new array in sorted order. O(n^2) O(n^2) would be to use two for loops to compare each element in the array with every other element in the array. For linear, you could push all elements into a hash as key and assign value 1 to each key. This would get rid of duplicates. Then get all keys and push it back to the array. hash select is O(n). What if the hash function is "return 0"? it degenerates into a linked list. Not sure how you can do this in O(n). If the values are integers of a set size, you can use a lookup table or sort in O(size*n) . Otherwise sort O(nlogn) Show More Responses You can use a hash. Either assume that you have a good hash function or write one (I doubt the interviewer would ask you to do a very complex hashing, but he'd appreciate you telling him about the assumption you made). Instead of the solution by venk T, I'd suggest another easier one. For every values you have, push it to the hashtable, usually a standard hashtable will return true or false depending on whether the value is already in the hashtable. If the value is not already in hashtable, output it in your answer, otherwise don't output. This will cut the last step of getting all the values off the hashtable. |

**1**–

**10**of

**6,062**Interview Questions

## See Interview Questions for Similar Jobs

- Mechanical Engineer
- Intern
- Engineering Intern
- Engineer
- Engineering
- Mechanical Design Engineer
- Mechanical Engineering
- Software Engineer
- Design Engineer
- Manufacturing Engineer
- Product Design Engineer
- Mechanical Engineer I
- Senior Mechanical Engineer
- Process Engineer