Intern Interview Questions | Glassdoor

# Intern Interview Questions

From retail to finance to medicine, every industry needs interns to provide additional support and assistance. Interview questions will vary greatly depending on the industry and role you are looking for. Expect to answer questions about how you work on teams and provide examples of any relevant work experience. To ace your interview, make sure to research the particular position you are applying for.

## Top Interview Questions

Sort: RelevancePopular Date

Jul 28, 2009

Oct 29, 2011

### Intern at Jane Street was asked...

Mar 14, 2011

Dec 9, 2013
 Find the max value in an array. The array is "semi-sorted". Here is an example: { 1 3 4 7 9 10 12 13 12 6 3 } As you can see, the array increases and then decreases at one point (13). 18 AnswersSimply walk the array to find the max in O(n) time. Compare the current max to the next element all the way until the end of the array.O(logn) approach: int max_value_in_semisorted_array(int* arr, int start, int end) { if (start == end) return arr[start]; int middle = (end + start) / 2; if (arr[middle] > arr[start]) return max_value_in_semisorted_array(arr, middle, end); else return max_value_in_semisorted_array(arr, start, middle); }No, your O(logn)-approach doesn't work. Try this: 1 5 8 10 9 8 7 6 5 4Show More ResponsesThe previous O(log n) approach doesn't handle arrays of odd length. int findPeak(int * array, int start, int end) { if ((start == end) || ((start == (end - 1)) && (array[start] > array[end]))) return array[start]; if ((start == (end - 1)) && (array[start] > array[end])) return array[end]; int middle = floor((start + end) / 2); if (array[middle] > array[start]) return (findPeak(array, middle, end)); else return (findPeak(array, start, middle)); } Remember to include math.h for the floor function.It seems, that it doesn't matter if the array is of odd or even length(btw, my example is not odd :)). This approach doesn't work when the max element is in the first half of your array and the middle element is greater than the first one. We cannot guarantee that if the middle element is greater than the first, our array increases monotonically from x[1] to x[middle] and we should search the max element in the range from middle to end.It is necessary to check two elements on each side of our middle element to find out where the array increases , where decreases, and where the peak is. And only then we can guarantee something about our max.The maximum is obviously just the inflection point in the list... some of the posted solutions here are absurdly complex for this.Brute force solution can be ofcourse O(N). But we can make it better: mid = (start + end )/2 if mid > mid + 1 && mid > mid - 1 return mid else if mid mid -1 search mid -> end else if mid > mid + 1 && mid mid@Mo - This won't be work for an array where the max element is hidden in the first / second half of the main array. Eg: {1,3,9,1,-2,6,2,2,5,-1}In your test case, I see that the numbers increase, decrease, increases, decreases and so on. I thought the question says the list is semi sorted. So my program assumes that the numbers increase and then decrease. We need to find the peak. At least that is my understanding.private static int recFindPeak(int[] a, int start, int end) { if(start == end) return a[start]; int mid = (start+end)/2; if((a[mid] > a[mid+1])&&(a[mid] > a[mid-1])) return a[mid]; else if(a[mid] > a[mid-1]) return recFindPeak(a, mid+1, end); else return recFindPeak(a, start, mid-1); }My codes: int findPeak(vector num) { if (num.empty()) return 0; int lower = 0; int upper = num.size()-1; while (lower num[mid+1]) return num[mid]; else if (num[mid-1] < num[mid] && num[mid] < num[mid+1]) lower = mid+1; else upper = mid-1; } }1. Walk from begin to mid comparing a[i] a[j] and stop decrementing j when this condition fails. 3. If a[i] < a[j], then return a[j], else return a[i].Show More Responses1) find the pivot of the highest number of the semi sorted list ,using binary search on the array.(logn) 2) From their do the linear serach for finding max ,also compare with last element of the semi sorted list.public class KindsOfQuestion { static int Max(int[] arr, int start, int end) { //int max=0; if (start == end) return arr[start]; if((end-start)==1 && arr[end]>arr[start]) { return arr[end]; } if((end-start)==1 && arr[end] arr[start]) if (arr[middle] > arr[middle-1]) return Max(arr, middle, end); else return Max(arr, start, middle); } public static void main(String[] args) { int[] arr=new int[]{1,5,8,10,9,8,7,6,5,4};//,TODO,Auto-generated,method,stub System.out.println("Max is:"+Max(arr,0,arr.length-1)); } }strange, some lines missing for above solution: shouldn't be one line : if((end-start)==1 && arr[end] arr[start]) but: if((end-start)==1 && arr[end]<=arr[start]) { return arr[start]; }def maxInSemiSortedArray(inputData): low, high = 0, len(inputData) -1 while(low inputData[mid-1] and inputData[mid] > inputData[mid+1]: return inputData[mid] elif inputData[mid] < inputData[mid+1]: low = mid + 1 else: high = mid -1def maxInSemiSortedArray(inputData): low, high = 0, len(inputData) -1 while(low inputData[mid-1] and inputData[mid] > inputData[mid+1]: return inputData[mid] elif inputData[mid] < inputData[mid+1]: low = mid + 1 else: high = mid -1

### Trader Intern at Jane Street was asked...

Jan 12, 2011
 Russian Roulette - 4 blanks 2 bullets, all in a row. If someone shoots a blank next to you, would you take another shot or spin 12 Answerstake another shot, 3/4 chance of surviving vs 2/3 if you respinHere is my answer: the prob. of survival after re-spin is: 3/5. the prob. of survival with on re-spin is: 1/15 * 6/4 = 1/10.correction: the prob. of survival after re-spin is: 4/6.Show More Responsesmy final correction: the prob. of survival after re-spin is: 4/6 = 2/3 the spin with no spin is: 2/5 = c(4, 2) / c(6, 2).Denoting the blanks by 0's and live bullets by 1's, and adjoining the left and right edges (denoted by ~) , so as to make a cylinder, the following diagram illustrates how the bullets are arranged in the cylinder of the revolver: ~000011~ . Denote the bullet that is to be fired if the trigger is pulled by enclosing it in parenthesis. Denote an empty chamber by *. Assume that when you pull the trigger, the cylinder rotates clockwise (to the right in the diagram above). If when you pulled the trigger for the first time, the bullet was a blank, then before and after you pulled the trigger, the cylinder was and is in one of the following states: 1) Before: ~(0)00011~ After: ~*0001(1)~ 2) Before: ~0(0)0011~ After: ~(0)*0011~ 3) Before: ~00(0)011~ After: ~0(0)*011~ 4) Before: ~000(0)11~. After: ~00(0)*11~ If you pull the trigger again without spinning the cylinder, then only in case one will the bullet be a live bullet, yielding a 3/4 probability of the bullet being a blank . If you spin the cylinder and then pull the trigger, then you have a 4/6=2/3 probability of the bullet being a blank. Clearly, you should not spin the cylinder.don't spin, 3/4 prob survival if not spinnedrespin - 4/6 = 2/3 (obvious) don't spin - you only die if the blank was the "last" one, which is 1/4 chance. hence 3/4 chance of live. since 3/4>2/3 don't spin.Wouldn't play.Spin Spin: 4/6=0.6667 to survive Not Spin: C(4,2)/C(5,2)=3/5=0.6condition on 2 bullet is in consecutive position and someone survives the 1st shot, we have: spin it-> survival rate is 4/6=2/3=67% not spin it-> survival probability=3/4=75% so...not spin it will have a bigger chance of survival.the question did not say that the bullets are next to each other so in this case you should spinI. Using Bayes' Theorem: P[0] = probability of a blank : 4/6 P[1] = probability of a bullet : 2/6 P[1|0] = probability of a bullet given a blank : find this P[0|1] = probability of a blank given a bullet If a bullet occurs then the next pull can be a bullet or a blank and so P[0|1] = 1/2 P[1|0] = P[0|1]*P[1] / P[0] = 1/4 So there is a 25% chance that the next pull is a bullet, or a 75% chance that it is a blank. The first pull had a probability of 8/12 of being a blank. Given a blank on the first pull, the second pull has a 9/12 probability of being a blank. II. From a frequentist perspective: So when the first pull is made and it is a blank the event space decreases from 6 possible outcomes to 4 possible outcomes. The first pull was on the last bullet or the the first pull was on the second to last blank. Out of the four possible events there is one where after the pull the chamber is sitting on the blank right before the bullet. Out of the four events 3 are blanks (3/4) and 1 is a bullet (1/4).

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

Feb 7, 2011
 Implement a power function to raise a double to an int power, including negative powers.11 AnswersCould be implemented many ways. I got the feeling that the interviewer wanted to see you approach the problem in multiple ways and demonstrate confidence in your math and recursive skills.#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; } }c implementation of the above (no recursion): int ipow(int base, int exp){ int result = 1; while(exp){ if(exp & 1) { result *= exp; } exp >>= 1; base *= base; } return result; }Show More Responsesint power(double n, int exp) { bool npower = (exp < 0) ? true : false; double result = 1; exp = abs(exp); // get the absolute value for (int i = 0; i < exp; i++) { if (npower) { result = result/n; } else { result = result*n; } } return result; }C# code verified: static double Power(double d, int exp) { if (d == 0 || exp == 0) { if (exp >= 0) { return 1; } else { return double.PositiveInfinity; } } int expAbs = Math.Abs(exp); double res = d; for (int i = 1; i 0) ? (res) : (1 / res); }double power(double x, int y) { if(y == 0) return 1; int sign = 1; if(y < 0) sign = -1; y = abs(y); double d = power(x, y/2); if(y%2 == 0) d = d*d; else d = x*d*d; if(sign == -1) return 1.0/d; else return d; }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...I believe interviewer is expecting for this public static double Power(double x, int y) { double result = 1; bool isNegative = y 0) { if ((y & 1) > 0) { result *= x; } y = (y >> 1); x *= x; } if (isNegative) result = 1 / result; return result; }Verified C# static double Pow(double b, double exp) { if (exp == 0) return 1; else if (exp > 0) return b * Pow(b, exp - 1); else return 1 / Pow(b, -exp); } Does it get more compact?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.public double power(double num, int exp) { if(exp == 0) return 1; double res = 1; for(int e=Math.abs(exp);e>0;num*=num,e>>=1) { if( (e&1) == 1) res *= num; } return (exp>0)?res:1.0/res; }

Mar 11, 2011

Mar 17, 2013

### Summer Trading Intern at Jane Street was asked...

Oct 4, 2011
 Say I take a rubber band and randomly cut it into three pieces. What's the probability that one of the pieces has length greater than 1/2 of the original circumference of the rubber band.9 Answers3/4Suppose you have two cuts on the rubber band placed randomly. The probability of having one segment greater than half the circumference is the probability that the third cut will be inside the combined range of 90* to either side of the cuts. Since the average distance between the first two cuts is also 90*, the combined range is 270*, or 3/4 of the circle.You need 3 cuts to end up with 3 pieces. The first cut doesn't matter. The second cut can also be anywhere and the largest piece will still be at least half the circumference. What matters is the third cut, which should lie in the same half as the second cut. So the probability is actually 1/2.Show More ResponsesThe correct answer is 3/4, as this problem is equivalent to the famous 3-points-on-semicircle problem. Why? If one of the pieces has length greater than 1/2 the circumference, then the three points of cutting must lie in the same semicircle. On other hand, if the three points of cutting lie on the same semicircle, then the longest piece must be at least 1/2 of the circumference.For reference to the 3-points-on-same-semicircle problem, see e.g., http://godplaysdice.blogspot.com/2007/10/probabilities-on-circle.html1/4 1 -3/4suppose I have two points whose minor arc distance is t <= 1/2. Then the range of semicircles covering both points gives an arc length of (1/2+1/2)-t = 1-t. say we fix the first point, tracing the second point around gives minor arc lengths from 0 to 1/2 and then 1/2 to 0. Therefore the answer is 2*integral (1-t) from 0 to 1/2, which is 2(1/2-1/8) = 3/4It's 3/4. Cut it into 1 piece make a line. Cut it close. Pretend the length is 100. If you cut the first at x=1, as long as it isn't between x=50-51, it will have a length greater than 50% so there's 99% chance. You can imagine that if the cut was infinitely close to the end it would be about 100%. Now cut at x=2 you can't do between x=50-52. For x=3 it's 50-53 etc. So when you get to right to infinitely close to 50 it is pretty much between x=50-100 so there is a 50% chance you hit your spot. (obviously 50-50 is 100%, but since this length is continuous there's little chance it lands on that point). Obviously since this is symmetrical you can see this pattern going from 50% to 100% at the other end. Since each point on the continuous line has the same probability of happening the answer is clearly 75%.This problem is also equivalent to the probability that, if you have a line segment from 0 to 1 and you make 2 random cuts on that line segment, what is the probability that the three resulting pieces do NOT make a triangle?

Apr 17, 2011