# 8K

Software Intern interview questions shared by candidates

## Top Interview Questions

Sort: Relevance|Popular|Date
Software Engineer Intern was asked...28 July 2009

### 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?

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

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?

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.

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 a number n, find the largest number just smaller than n that can be formed using the same digits as n.

package interview; import java.util.Arrays; import java.util.Scanner; public class LargestNumberBeforN { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String a = sc.next(); for (int i = a.length() - 1; i &gt; 0; i--) { if (a.charAt(i) = 0; i--) { b = b + String.valueOf(a[i]); } return b; } } Less

Approach. Traverse from the last till u get a number that is greater than previous number.. Put last digit before this new number and the rest of digits in reverse order after this greater number. #include #include using namespace std; int main() { int n,newN,newNumber=0,old=9; cin&gt;&gt;n; int numberToAdd=n%10; int i=0; n=n/10; while(n&gt;0) { newN=n%10; if(old Less

My answer did not show properly: public static int smaller(int n){ if(n less than 10) return n; int d0 = n % 10, n2 = n / 10, d1 = n2 % 10; if(d1 greater than d0) return n / 100 * 100 + d0 * 10 + d1; return smaller(n2) * 10 + d0; } Less

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

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 &gt;= 0 || j &gt;= 0){ int d1 = 0; int d2 = 0; if (i &gt;= 0) d1 = num1[i--] - '0'; if (j &gt;= 0) d2 = num2[j--] - '0'; int sum = d1 + d2 + carry; if (sum &gt;= 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 &gt;= 0 || pointerB &gt;= 0){ int a = pointerA 10) { carry = sumTemp / 10; sumTemp = sumTemp % 10; } else { carry = 0; } sb.insert(0, sumTemp); } if(carry &gt;0) sb.insert(0, carry); return sb.toString(); } Less

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

For a Y shaped like this: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt;7 -&gt; 8 -&gt; 9 5 -&gt; 6 -&gt; 7 -&gt; 8 -&gt; 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

i think that kvr's answer is the best. @snv if the two lists are linked by the very last two nodes, then you would find out after you are checking the values of the second two last two nodes. you just got unlucky and basically have to check until the very end. so basically, as a diagram with your example, it would look like this 1 -2 -3 -4-7-8-9 x -x -x -x -x-o 12-13-14-5-6-8-9 (sorry about spacing) but because you know the difference in length is 0, you can start comparing the two lists of nodes one by one. from the very beginning. Less

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

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' &amp;&amp; N[i+1]&lt;'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?

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

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.