# Engineering Intern Interview Questions

Engineering intern interview questions shared by candidates

## Top Interview Questions

### Mechanical Engineer Intern at Nokia was asked...

If you have a refrigerator in an isolated room (no heat in or out) and left the door to the refrigerator open, what would happen to the temperature to the room? Would it go up, down or say the same? 11 AnswersIf the door to the refrigerator is left open, the frige has to work harder because now it has to try to cool the entire room rather than just the inside of the frige. The coils and condenser in the back of the frige would create more heat thus heating the room up. The temperature of the room would stay the same - the key is the fact that it is in an isolated room. There is no heat exchange between the room and it's external surroundings. The refrigerator will warm up the room. If you look on the back of the refrigerator, you will see metal grating. Touch it. Its warm! A refrigerator is transporting heat from the inside cavity to the outside. However, the power cord running from the wall is pumping energy into the refrigerator/room. Energy is powering the refrigerator. It is also running an irreversible process, the energy dissipates out as heat and work (mostly heat), making the net temperature of the room increase. Show More Responses I propose the room remains constant - but for the following reason. The room is reported to be isolated. I denote that to be a cube with no walls, windows, doors, plumbing, OR conduit or an electrical box that would allow cable or air to move within or without the isolated cube. Logically, in that the fridge is not powered, it is not generating heat through the use of the motor, condenser or heat - exchange coils. Really, it doesn't matter what the answer is... you've just got to defend it logically. If the fridge were powered - but was an excessively large model (as you might find in a grocery store walk in) the room might cool. If it were a smaller unit - the motor would have to work overtime to try and keep it cool - thus heating the room. Just be creative! That's what they're looking for. Can you think on your feet. Aa The room's temperature will be exactly as the refrigerator's temperature. Heat will be absorbed by the grating metal on the back of the refrigerator, so no need to worry about where the heat that refrigerator produces go. Majority of the answers here are wrong. A refrigerator is a heat pump that move thermal energy opposite to the direction of spontaneous heat flow by absorbing heat from a cold space and releasing it to a warmer one. There is some work required to move this thermal energy from Cold to Hot. If we assume that the amount of work used to move this energy is negligible, if you leave a refrigerator door open in an isolated room, the room temperature will stay the same. https://en.wikipedia.org/wiki/Heat_pump https://en.wikipedia.org/wiki/Refrigerator If its an isolated room the frig will not be able to be plugged in to an outlet. So remains the same The room temperature will remain the same. The reason for this lies in its basic principle of vapor compression cycle. Its true that refrigerator transfers the heat from one place to another. But one has to remember that the door is open. So, As heat is extracted by refrigerant and thrown in room using condenser and since the room is isolated and refrigerator door is open.. the same heat will be added inside refrigerator and same refrigeration cycle continues after that. In a way refrigerator is not able to cool anything. it is just continuously maintaining energy equivalence. In this case, there is a net gain of energy from the refrigerator outlet into the room and no loss of energy out of the room. Thus, the room will warm up since there is a gain of energy. Part of the room's temperature would decrease slightly. The other part of the room's temperature will stay the same. Since the refrigerator's energy is not large enough to cool the whole room it will cool a small portion of the room. |

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

Given an unsorted array, extract the max and min value using the least number of comparison. 4 Answersf(1)=1 f(2)=f(1)+1=2 f(3)=f(2)+f(1)+1=4 ... var min, max, arr = [3,4,2,7,1,9]; for(i in arr){ //n-iterations min = Math.min( arr[i], arr[i+1], min ); //2 comparisons max = Math.max( arr[i], arr[i+1], max ); //2 comparisons } //4n => n well normal case n comparisons Compare in pair and you have n-1 comparisons... Show More Responses Minimum number of comparisons is 3n/2. The strategy is to go through the elements in pairs, and compare the smaller one to the minimum, and the bigger one to the maximum. This is 3 comparisons, done n/2 times in total, for 3n/2 running time. Working code in python: import random import sys r = [random.randint(1,100) for i in range(31)] print r mini = r[0] maxi = r[0] start = 0 if len(r) % 2 != 0: start = 1 for i in range(start,len(r)-1,2): n1 = r[i] n2 = r[i+1] # Exactly 3 comparisons each time if(n1 < n2): mini = min(n1,mini) maxi = max(n2,maxi) else: mini = min(n2,mini) maxi = max(n1,maxi) print mini print maxi |

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

Given a number n, give me a function that returns the nth fibonacci number. Running time, space complexity, iterative vs. recursive. 5 AnswersLet me give you a recursive & not-efficient solution to get n th fibonacci number. public int findNthFib(int n) { return (n < 2 ? n : (findNthFib(n-1)+findNthFib(n-2)); } This short method will recursively return fib number. However, running time is very awful! it's O(2^n) = exponential time. it will quickly become a non-usable method after n = 30~40. There is another quick and elegant linear time solution, but I want the next person to present that in here. (if you google it, you can find it easily) unsigned long long fibonacci(unsigned long long n) { unsigned long long c = 0; unsigned long long i = 1; unsigned long long j = 0; unsigned long long nfib = -1; while (c < n) { i = i + j; c++; if(c == n) { nfib = i; cout << i << " "; break; } j = j + i; c++; if(c == n) { nfib = j; //break; } cout << i << " " << j << " "; } cout << endl << nfib; return nfib; } Time complexity O(N/2). Closed form solution. GG Show More Responses int public(int n){ if(n == 0) return n; if(n == 1) return n; return (n-1)+(n-2); } public class fib { public static void main(String args[]){ int n=12; int counter=2; int[] arr = new int[n+1]; arr[0]=1; arr[1]=1; while(counter<n+1){ arr[counter]=arr[counter-1]+arr[counter-2]; counter++; } System.out.print("answer is "); System.out.print(arr[n-1]); } } |

Can you think of an example of a scenario where you would want to use a tree with more degrees of branching than a binary tree? 4 AnswersIf you need to represent a company's personal structure. For example, one president is trailed by more than just two vice presidents and it will span.... Great example for this: modeling a dictionary of possible words. I.e. a->g->r works because aggregate but a->g->(g) wouldn't because the second g wouldn't exist in the tree (no words begin or are formed with the string "agg"). I've actually received this in an Amazon interview where I was asked to model the game Boggle. B-Tree Show More Responses Database indexes is a classic example |

string compression: aaabbbbcc ->a3b4c2 5 AnswersJava code: private static String compressString(String input) { StringBuilder result = new StringBuilder(); char currentCharacter; int count; for(int i = 0; i < input.length(); i++) { currentCharacter = input.charAt(i); count = 1; while(i < input.length() - 1 && input.charAt(i + 1) == currentCharacter) { count++; i++; } result.append(currentCharacter); result.append(count); } return result.toString(); } //C++ using namepsace std; main(int argc, char** argv) { string input = "aaaabbccccddd"; string output; char lastchar = input[0]; int count = 0; for (int i = 0; i < input.size(); i++) { if (input[i] != lastchar || i == input.size() -1 ) { output += lastchar; output += count; count = 0; lastchar = input[i]; } count++; } } What is a character is repeated more than 10 times? aaa..14times..bbb.cc.. a14b3c3 - how do we decode it then? if we assume input string can contain only alphabets- then its fine. Show More Responses Make an array of size 256 for all ASCII characters. Iterate through string and increment each character that matches the array. Iterate through ASCII array and concatenate letters and element values I'd probably just use a hash map (in-order map just like C++'s map) and iterate through the string counting the number of occurrences of each character. Then, using the in-order property of the hash table, the string could then be printed out in the aforementioned format: aaabbbbcc ->a3b4c2. |

Explain tail recursion. 3 Answerstail recursion is tail recursion Tail recursion does computation before recursive calls. A typical implementation is to pass the current result as a parameter to recursive call. A tail recursive function is one that performs a recursive call as its final step. Tail recursion is important because it can be more efficient - you can reuse the same stack frame for the next call, saving some time and memory. For example, a NON tail recursive Fibonacci function in OCaml (forgive me if I mess the syntax up any, most of the functional programming I've done is in Haskell): let rec fib n = match n with 0 -> 1 | 1 -> 1 | n -> fib (n - 1) + fib (n - 2) Obviously, the call to fib isn't the last thing that gets evaluated. That'd be the sum of the two recursive calls. Here's a tail recursive Fibonacci function, from Literate Programming Wiki: let fib n = let rec aux n b a = if n <= 0 then a else aux (n-1) (a+b) b in aux n 1 0 It works by "carrying along" the present sum as an argument in the aux function. That way, each call of aux can only make one recursive call (in the else branch), and the Fibonacci numbers are calculated as part of that recursive call. |

Given an array of integers, all but one of which appears an even number of times, find the one integer which appears an odd number of times. Upon completion, asked to improve the algorithm in terms of both time and space, eventually asked to do it in O(n) time and constant space. 4 Answersxor the entire array, all the integers which appear an even number of times will cancel eachother out int[] theArray = new int[]{1, 1, 2, 2, 3, 3, 3, 4, 4, 10, 10, 10, 10, 10, 11, 11, 12, 12}; Map theMap = new HashMap(); for (int i = 0; i mapKeys = theMap.keySet(); for(int keyInt : mapKeys) { if(theMap.get(keyInt) % 2 != 0) { System.out.println(keyInt + " occurs odd number of times"); } } } I was also asked this in 2010,march. Show More Responses XOR |

### Software Engineering Intern at Zillow was asked...

Given a word and a list of valid English words, return a list of all valid words that can be made by permuting the characters in the given word. 3 AnswersI described and wrote pseudocode to build a trie from the list of valid words and then do a recursive backtracking search on it. That may have been overly complicated though. This is the answer I could come up with. Correct me if i'm wrong. Assign prime numbers(don't include 2) to each of the alphabets(ex: a=3,b=5,c=7) Write a custom hash function which multiplies the values of the letters in the word. Hash the list of words given using this function. Each time the same key appears increase the count for that value. Now when the word is given, its permutation can be found in constant time. Sort the given word. Use that sorted string as a key or comparator. Iterate through the raw list of English words, sorting each one and compare that sorted version to the given word's key. If they are equal, then add to a HashSet. One should keep in mind that the question asks for valid English words, which would never be long nor arbitrary. This means that the sorting of each entry would not be expensive. This should run in O(n) time, where n is the size of the list of valid English word. |

Write a program to reverse a string 3 AnswersString reverse(String s){ int length = s.length()-1 String s1 = "" while (length >= 0){ s1 = s1 + s[length] length-- } return s1 } forget semicolumns (;), sorry Push char by char on a stack then concatenate all the pops until the stack is empty. |

Calculate the square root of a number. 3 Answerspublic double squareRoot(double x) { double epsilon = 0.000001; double base = 0; double increment = 1; while (increment > epsilon) { double diff = base*base - x; if (diff 0) { base -= increment; increment /= 10; } else { break; } } return base; } private static double sqrt(double n) { double lower = 0; double upper = n; for (int i = 0; i < 1000; i++) { double mid = (lower + upper) / 2; if (mid * mid < n) lower = mid; else upper = mid; } return (lower + upper) / 2; } #include #include using namespace std; #include int main() { float n; cout>n; if(n0.00001) { if(mid*midn) high=mid; mid=(low+high)/2; } return mid; } |

**41**–

**50**of

**1,940**Interview Questions

## See Interview Questions for Similar Jobs

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