# Engineer intern Interview Questions

# 7K

Engineer Intern interview questions shared by candidates### Suppose you had eight identical balls. One of them is slightly heavier and you are given a balance scale . What's the fewest number of times you have to use the scale to find the heavier ball?

47 Answers↳

Two. Split into three groups of three, three, and two. weigh the two groups of three against each other. If equal, weigh the group of two to find the heavier. If one group of three is heavier pick two of the three and compare them to find the heaviest. Less

↳

2 3a+3b+2 = 8 if wt(3a)==wt(3b) then compare the remaining 2 to find the heaviest if wt(3a) !== wt(3b) then ignore group of 2 discard lighter group of 3 divide the remaining group of 3 into 2+1 weigh those 2 If == the remaing 1 is the heaviest if !== the heaviest will be on the scale Less

↳

2 weighings to find the slightly heavier ball. Step 1. compare 2 groups of three balls. Case 1. if they are both equal in weight, compare the last 2 balls - one will be heavier. case 2. If either group of 3 balls is heavier, take 2 balls from the heavier side. compare 1 ball against the 2nd from the heavy group result 1. if one ball is heavier than the other, you have found the slightly heavier ball. result 2. if both balls are equal weight, the 3rd ball is the slightly heavier ball. Easy Shmeezi Less

### non disclosure agreement

18 Answers↳

I don't actually know. I mean, that's what I would do if I were amazon, but I did not read anything about them webcamming me, and I also didn't happen to notice the webcam light being on. That didn't mean it didn't happen, though. Less

↳

I took the test in c++. The function interfaces were in base c, though, so it would probably look more or less identical in c or java. Less

↳

Hi, I just finished my second assessment test for Amazon and passed all their tests for the 2 coding questions. Was the second test really the final round? There isn't a final third round? Thanks! Less

### What was one of your best achievements on a project in the past?

18 Answers↳

From what i've heard and seen, just wait, following up will barely do you any good. Less

↳

Hey, I just have one question out of curiosity, was the second online assessment web-cam proctored? Less

↳

i heard amazon is changing their recruiting process. Many people complained that the online proctoring was an invasion of their privacy. I also had a second online assessment but it was not webcam proctored. I am assuming the recruiting process is now two online non webcam assessments then a final phone interview. My friend had that round of interviews with Amazon 2 weeks ago. Less

### DS, Algorithms.

18 Answers↳

Review Leetcode, CTCI.

↳

Hi, did you interview on Jan 27? Did the engineer ask about behavioral questions or resume questions or did they just jump right into the coding questions? Also I finished my second assessment a week ago but still didn't get a reply back. Was that normal for you? Less

↳

Hi, did you interview on Jan 27? Did the engineer ask about behavioral questions or resume questions or did they just jump right into the coding questions? Also I finished my second assessment a week ago but still didn't get a reply back. Was that normal for you? Less

### Given two strings representing integer numbers ("123" , "30") return a string representing the sum of the two numbers ("153")

14 Answers↳

public static String sumStrings(String a, String b){ char[] num1 = a.toCharArray(); char[] num2 = b.toCharArray(); int i = num1.length - 1; int j = num2.length - 1; StringBuilder sumString = new StringBuilder(); int carry = 0; while(i >= 0 || j >= 0){ int d1 = 0; int d2 = 0; if (i >= 0) d1 = num1[i--] - '0'; if (j >= 0) d2 = num2[j--] - '0'; int sum = d1 + d2 + carry; if (sum >= 10){ carry = sum / 10; sum = sum % 10; }else carry = 0; sumString.insert(0, sum); } return sumString.toString(); } Less

↳

The interviewer wanted a loop through the digits starting form right to left, adding them one by one, and keeping track of the carriage. Less

↳

public static String addTwoStrings(String s1, String s2) { int len1 = s1.length(); int len2 = s2.length(); char[] s1Chars = s1.toCharArray(); char[] s2Chars = s2.toCharArray(); StringBuilder sb = new StringBuilder(); int pointerA = len1 -1; int pointerB = len2 -1; int carry = 0; while (pointerA >= 0 || pointerB >= 0){ int a = pointerA 10) { carry = sumTemp / 10; sumTemp = sumTemp % 10; } else { carry = 0; } sb.insert(0, sumTemp); } if(carry >0) sb.insert(0, carry); return sb.toString(); } Less

### Suppose we can translate numbers into characters: 1->a, 2->b, ...26->z given an integer, for example, 11223, output every translation of the number.

13 Answers↳

Well I think the first answer in totally wrong except the first one, Here is what I have: aabbc kvc alw kbw aavc aabw kbbc albc Less

↳

In Java, a recursive solution is: public static void main(String[] args) { String s = "11223"; char[] N = s.toCharArray(); char[] S = new char[N.length]; m(0,0,N,S); } public static void m(int i, int j, char N[], char[] S){ if (i==N.length){ System.out.println(new String(S, 0, j) ); return; } S[j]=(char)('a'+Integer.parseInt(""+N[i])-1); m(i+1, j+1, N, S); if (N[i]=='1' || (N[i]=='2' && N[i+1]<'7')) { S[j]=(char)('a'+Integer.parseInt(""+N[i]+N[i+1])-1); m(i+2, j+1, N, S); } } Less

↳

no body use dp?

### To find and return the common node of two linked lists merged into a 'Y' shape.

13 Answers↳

For a Y shaped like this: 1 -> 2 -> 3 -> 4 ->7 -> 8 -> 9 5 -> 6 -> 7 -> 8 -> 9 where the trunk portion is of constant length, it is easy. Get the length of the first list. In our case 7. Get the length of the second list: 5. Difference is 2. This has to come from the legs. So, walk the difference in the larger list. Now node1 points to 3. node 2 points to 5. Now, walk through the two lists until the next pointers are the same. Less

↳

@kvr what if the lists are 1-2-3-4-7-8-9 and 12-13-14-5-6-8-9

↳

how did the two linked lists make their poses to merge into a 'Y' shape, one's head attached to the waist? please explain more to help understand the question Less

### Determine if an array from 1..n has a duplicate in constant time and space.

13 Answers↳

If an array has elements from 1 to n the size of the array will be n, thus if the size of the array is greater than n, there must exist a duplicate. Less

↳

What are the properties of an array that affect time complexity? Usually we're talking about the size of the array, N, such that linear time operations, O(N), are those that perform an operation on each of the elements in the array. However, an important thing to consider is that you can evaluate N (the size of the array) itself in constant time. The only way this can be done in constant time is if the input satisfies the precondition that "1..n" means there are no *missing* values in that range. In other words, such an array from "1..5" must contain at least one instance of the numbers 1, 2, 3, 4, and 5. With that precondition, you know that the length of the array will be 5 if no duplicates and greater than 5 if it does contain duplicates. Less

↳

SUM(array) - (N(N+1)/2) = missing number.

### 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 Answers↳

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. Less

↳

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. Less

↳

The temperature and overall heat content of the room will increase. Yes, the fridge it providing cooling, but it is doing this by removing heat from part of the air and dumping it into other parts of the air, all while doing work which is harnessed from the power input (electricity) from the wall. In other words, the heat in the air is just displaced from one area of air to another, so no loss nor gain of net heat, HOWEVER the work used to do this creates additional heat. If you consider this from a total energy standpoint, all energy within the room is fixed, except there's energy being added through the power input, so there's an increase in energy with time. I'm shocked at some of the other answers here, I hope those saying the temperature remains the same do not have mechanical engineering degrees. Less

### An optimal algorithm to check whether a hand of cards was a full house (in Poker) or not.

9 Answers↳

Check first card, store number of card, set first counter to one Check number of next cards - If different card, store number of card, set second counter to one, break - If same card, increment first counter, check if greater than three: - If less or equal to three, continue - If greater than three, return false Continue checking cards - If matching either stored card, increment respective counter, check if >3 - If less or equal to three, continue - If greater than three, return false - If not matching either card, return false Return true Less

↳

1. Draw first card. card1 = firstCard and count1 = 1 2. Draw next card x and repeat upto step 12 for all cards 3. If (card2 != null && (x!=card1 && x != card2) 4. return false 5. if(x == card1) 7. count1++; 8. if(card2 == x) 9. count2++; 10. if (card2 == null) 11. card2 = x and count2 = 1 12. go to step 2 13. if(abs(count1-count2) == 1) 14. return true 15. else return false public static boolean isFullHouse(String[] s){ int count1 = 1, count2 = 0; String card1 = s[0], card2 = null, nextCard; for(int i = 1; i < 5; i++){ nextCard = s[i]; if(card2 != null && (!nextCard.equals(card1) && !nextCard.equals(card2))) return false; if(nextCard.equals(card1)) count1++; else if(nextCard.equals(card2)) count2++; else if(card2 == null){ card2 = nextCard; count2 = 1; } } if(Math.abs(count2-count1) == 1) return true; else return false; } Less

↳

Most optimal and easy in my opinion: 1. Cards are represented as int : 2, 3, .., 10, 11='J', 12='Q',13= 'K',14= 'A' 2. Hand is build of n cards vector hand int bits; for(int i=1; i<5; i++){ if(bits&(1< Less