Software intern Interview Questions

8K

Software Intern interview questions shared by candidates

Top Interview Questions

Sort: Relevance|Popular|Date
Goldman Sachs
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?

48 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

Show More Responses
Amazon

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

Show More Responses
Amazon

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

Show More Responses
Amazon

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

Show More Responses
Meta

Given a number n, find the largest number just smaller than n that can be formed using the same digits as n.

16 Answers

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 > 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>>n; int numberToAdd=n%10; int i=0; n=n/10; while(n>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

Show More Responses
Meta

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

Show More Responses
Amazon

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

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

Show More Responses
Meta

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?

Show More Responses
Microsoft

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.

Show More Responses
Meta

Implement a power function to raise a double to an int power, including negative powers.

11 Answers

#include #include #define MAX_ARRAY_LENGTH 256 double power(double, unsigned int); int main(int argc, char** argv) { double a = atof(argv[1]); int b = atoi(argv[2]); double result = power(a, b >> 31 == 0 ? b : -b); if ((unsigned int) b >> 31 == 1) { result = 1 / result; } printf("%f\n", result); return 0; } double power(double a, unsigned int b) { switch (b) { case 0: return 1.0; case 1: return a; default: return (b & 1) == 0 ? power(a * a, b >> 1) : power(a * a, b >> 1) * a; } } Less

I am surprised that not a single person here had noticed that the guy asked to raise a DOUBLE to a given power. Men, double are not integers. Their exponent is stored in a part of their binary representation. If you multiply n times a double you will make n times a rounding error and n useless calculations. Just changed the binary part of the double that is related to its exponent, and here it is, your double has been raised to a given power, a you absolutely lost no precision, and you've made 0 calculations. This is basic stuff, every university teaches that to its students... floating numbers representation... Less

TD's answer is interesting, but not very useful. If you actually try it you'll find that since the double's base is 2, any changes to the exponent portion approximately multiply (or divide) numbers by a power of two. I say approximately here, since TD forgot to mention that the number itself isn't stored in float point numbers, only the digits after the implied 1. So yes, it's important to know how floating point numbers work, but modifying the exponent portion of a floating point number is a fundamentally incorrect solution. Less

Show More Responses
Viewing 1 - 10 of 8,485 Interview Questions

See Interview Questions for Similar Jobs