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

Software Engineering Intern at Facebook was asked...

Mar 8, 2012
 Given a sorted array, write a program to decide if two elements sum up to a third.9 AnswersDid you coded a solution < O(n^2 + logn) ?Assuming each number only appears once: //Java code public static void targetsum(int[] arr, int target) { if(arr == null) return; int start = 0; int end = arr.length -1; while(start target end--; } }typedef vector vint; bool check_element_sum(vint &array) { // n^2 algorithm sort(array.begin(),array.end()); //general case : nlogn copy(array.begin(),array.end(),ostream_iterator(cout," ")); cout=0;--i) //n^2 { start=0; end=i-1; target=array[i]; //note a<=b<=c for the tuples formed here hence check for c=a+b only while(startShow More Responsesthe algorithm for 3 elements sum up to a given number is also the same; the only change one needs to make is replace line target=array[i]; with target=total-array[i]; is there an algorithm with a lower order? says O( nlogn ); I am not able to think of anything!we can modify the 3sum algorithm for this.It is possible to do it in O(n) create a binary tree from the sorted array in O(n) subtract each value in array from target and find if its there in the tree, if found push to hash map, with the array item as key and the subtracted value as key next time before subtracting value in the array from target check if it is in the hash map@Pal the hash map gives a lower constan because /2 elements need to be checked but the lookup is still n*lognimport java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Random; import java.util.Scanner; import java.util.Set; public class SumOfTwoElements { public static void main(String[] args) { final Scanner in = new Scanner(System.in); final Random random = new Random(); while (true) { System.out.println("Enter array size : "); int size = in.nextInt(); int[] array = new int[size]; for (int i = 0; i > findSummingTriplets2(int[] array) { final Set> summingTriplets = new HashSet>(); for (int k = 2; k array[k]) { j--; } else if (sum > findSummingTriplets(int[] array) { final Set> summingTriplets = new HashSet>(); for (int i = 0; i end) { return false; } int mid = start + (end - start) / 2; if (array[mid] > value) { return contains(array, start, mid - 1, value); } else if (array[mid] < value) { return contains(array, mid + 1, end, value); } else { return true; } } }bool sumExists(vector nums, int target) { auto front = nums.begin(); auto back = nums.end() - 1; while (front != back) { if (*front + *back == target) return true; else if (*front + *back < target) front++; else back--; } return false; }

Mar 30, 2010

Trader Intern at Jane Street was asked...

Sep 20, 2011
 What if you could reflip 1 coin that you wanted. What would be the expected value then?6 AnswersSo I flip all my coins for the first time and my expected value is 2. Now, if all my coins are already heads (1/16 of the time) I stop and get \$4 (1/16*4) = .25 If I didn't get all heads the first time I select any one of the tails and re-flip, and then have a 50% chance of increasing my payout by \$1, or effectively, I theoretically increase my payout by (.5)(1) = .50 cents. So the final EV is: .25 + (15/16)(2.5) = 2.59375Not Quiteprob dist (1/16,1/4,6/16,1/4,1/16) for (4h,3h,2h,1h,0h,), payoff terminal node (4,4,3,2,1), EV(Risk Neutral)=41/16Show More Responsesit's 79/3279/32 is correct the post before was wrong to assume that a refip gets you a guarenteed headsusual expectation is 2, now we have to evaluate this option of flipping one additional coin. 1/16 of the time it's worthless, 15/16 of the time it's (conditional) value is 1/2. so the answer is 2 + 15/32 = 79/32

Summer Intern at Five Rings Capital was asked...

Apr 25, 2012
 • Is 1027 a prime number? • How would you write an algorithm that identifies prime numbers? • 2 blue and 2 red balls, in a box, no replacing. Guess the color of the ball, you receive a dollar if you are correct. What is the dollar amount you would pay to play this game? 8 AnswersAn algorithm for testing prime numbers is trial testing, test whether whether the number is dividable by an integer from 2 to its square root. For the color guessing game, the expected number of dollars you get is the average identity between a permutation of rrbb and rrbb, which is 2.For the prime number testing, only the number 2 and then odd numbers need to be tested. If it is not divisible by 2, there is no need to test against any other even number. So start with 2, then 3, then increment by 2 after that (3,7,9,...) until you are greater than the square root (then it's prime), or you find a divisible factor (it is not prime). To test for divisibility, we are looking for a remainder of zero - use a MOD function if available. Taking the integer portion of the quotient and subtracting from the actual quotient: if the difference is zero, then the remainder is zero and we have a divisible factor. If the difference is nonzero, then it is not divisible and continue testing. In this case, we find that dividing by 13 gives 79 with no remainder, so it is not prime.For the guessing game, the minimum winnings are \$2 every time with the proper strategy. I'm assuming the rules are you pay to play and you get to guess until there are no more marbles. Say you guess wrong the first attempt. (you guess blue and it was red). So now you know there are 2 blue, 1 red. Your logical choice is to choose blue again, since there are more of them. But say you guess wrong again. Now you know there are 2 blue left, so you will win on both of the last 2 draws. If you were correct on one or both of the first two trials, then you could wind up with an even chance on the third trial, so you would win that some of the time, then you'll always win on the last trial.Show More ResponsesDavid, I think we could pay more that \$2 and still come out on top. You logic seems sound, but looking at the probabilities I see: 1/2+1/3*(2)+2/3*(5/2) = 17/6 = ~2.83 Choosing the first ball, we obviously have an expected value of 1/2. Then, WLOG, we are left with RRB. Clearly we then choose R as this gives us a 2/3 shot at picking correctly. If it is R, then we get that \$1, have a 50% shot at the next, and are assured the last, giving us, on average, \$2.5. If it is B, then we know the next two will be R, giving us \$2. As you can see, with an optimal strategy, we should expect to make ~\$2.83 per round.Take the square root fo 1027. You get 32.04. Need only to check if divisible by prime numbers from 1 to 32, which include 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31 For algorithm, see Lucas' test on Wikipedia, where there is also pseudocode.1027 = 1000 + 27 = 10^3 + 3^3 and you know you can factor a^3 + b^31027 = 2^10-1 = (2^5-1)(2^5+1) prime number ez draw ball worths 17/6 dollars, the first draw worths 0.5, the rest worth(2/3 * 2.5 + 1/3 * 2)1027 = 2^10-1 = (2^5-1)(2^5+1) prime number ez draw ball worths 17/6 dollars, the first draw worths 0.5, the rest worth(2/3 * 2.5 + 1/3 * 2)

Jan 6, 2011

Software Development Engineer Intern at Amazon was asked...

Jan 6, 2011
 Write a program to find the square root of a double.5 Answersuse binary search to narrow down the search space and keep multiplying the answer in each iteration by itself to check if it is equal to the double given. If it is lesser, move up the lower bound, else move down the upper bound.One easy to remember method that also has much better performance than binary searching for the result is the Babylonian Method. It is similar to Newton's method for finding derivatives. See the algorithm here: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method Also, combining this algorithm with the Rough Estimation also described on that page will compute the squareroot of most double numbers in less than 10 iterations.Is it too obvious to ask if you can do double^.5 ?Show More ResponsesI would respond by showing that I am thinking about the problem as it is defined, not by making assumtions about what is implied. This can result in product that does not meet the requirement specifications, which can be very costly: "What do you mean, a program or a function? A program would require input and output mechanisms to make it meaningful, but makes it pretty usesless as a job assessment question. A function makes more sense in this context. "There's a variation of the problem which says "find the square root of a double up to the third decimal digit". I'd just multiply the original number by 10^position (meaning, for 3 digit accuracy it'd be 10^3) and ran a simple loop to find the closest integer. As soon as i*i > 10^position * number, you can return (i-1)/10^position. It's hella slow and unimaginative, but it works and you won't sound like you knew this problem ahead of time (if you come up with a Babylonian solution).

Software Engineer Intern at Motorola Mobility was asked...

Mar 19, 2009
 Write a function in Java that will take a sorted array of ints, possibly with duplicates, and compact the array removing all the duplicate numbers. That is, if the contains the numbers - 1, 3, 7, 7, 8, 9, 9, 9, 10, then when the function returns, the contents should be - 1, 3, 7, 8, 9, 10. Be sure your answer is as efficient as possible. Describe the efficiency of your algorithm using big O notation.5 Answerscreate temp array; starting from the second element copy the i'th char if input[i-1] != input[i] return tempoh efficiency is O(n)you can't create a temp array because you don't know the size until after you process. you could count the number of dupes in one pass, then allocate the array, then do the compacting. or you could allocate the array equal to the size of the original and accept that some elements will be null (or -1, or whatever). or you could use some dynamic data structure like an ArrayList to build the compacted list and convert it to an array at the end (ArrayList.toArray(...)). regardless, it's still O(n) and uses 2x the memory. makes me think there's a more elegant solution though.Show More Responsesdo bitwise XOR of consecutive numbers. When the xor is 0, you know the number is duplicate. It will require single pass thru the array to identify number of duplicates in the array.you can also use 2 index, at the beginning they both = 0, then you will have a previous and a next, if previous value = next value increment next index until next value != previous value then increment previous index by 1 and assign "next value" to it and so forth until you "next index reach the end of the array and then increment all previous index assigning null or -1. O(n) without using 2x memory. Anyway, I hope it is not too confusing, its late but I hope you got the big picture.

Software Engineer Intern at Hulu was asked...

May 3, 2012
 Write a power function power(a , b) returns a^b8 Answersint power (double a, int b) { for (int i = 1, i <= b, i++) { a *= a; } return a; }There are some conditions you are missing. What if b is <=0 ?The conditions made by the Hulu rep was to assume b > 0. However there is a better way to do this problem.Show More Responseslong power(int a, int n) { if(n%2==0) return power(a,n/2)*power(a,n/2); else if (n%2==1&&n!=1) return power(a,n-1)*a; else //n==1 return a; }double power(int a, int n){ double res=1; while(n!=0){ if((n&1)==1) { if(n>0) res*=a; else res/=a; } a*=a; n /=2; } return res; }def power(a,b): if b is 1: return a return a * (power(a, b--))double pow(int a,int b) { if(b0) { if(b%2==1) res*=a; a*=a; b>>1; } return res }def power(a, b): return a**b

Software Development Engineer Intern at Amazon was asked...

Jan 25, 2011
 Write a function that takes in an array and repeats an integer that appears the most.5 Answersif: Array [2][2][3][3][3][2][1][2][1] it should print [3]Confusing. In your example, 2 appears the most. Do you mean the integer that repeats the most consecutively? Cause that would be 3. Anyways, in either case, you can go through the array adding all the key-value pairs (number and times) to a hashmap and then access the hashmap in constant time. O(n).class FindMostOccurences { public static DictionaryEntry MostOccurences(int[] Array) { Hashtable ht = new Hashtable(); for (int i = 0; i Int32.Parse(de.Value.ToString())) { { de.Key = item.Key; de.Value = item.Value; } } } return de; } }Show More ResponsesUsing map , i think one loop is sufficient. private static int mostReapeatingNumber(int[] is) { HashMap map = new HashMap(); int tempHighestCount = 0; int keyHighest = 0; for (int index=0; index tempHighestCount) { tempHighestCount = numCount; keyHighest = number; } } } return keyHighest; }I think there's no need to have a map. Just maintain variables prev_max_run, prev_max_num, prev_num, curr_num and curr_run. In the loop if the prev_num was equal to curr_num increment curr_run. When you find the num is different check curr_run with prev_run. If curr_run > prev_run, prev_max_num = curr_num.

Software Engineering Intern at LinkedIn was asked...

Aug 24, 2012
 Traverse a binary there so that the order returned is ordered from smallest to greatest.5 AnswersIn order binary tree traversalvoid inorder (Node * root){ if (root) { inorder(root->left) coutvalue; inorder(root->right) } }This is a binary tree, not a binary search tree. Thus, in order traversal may not work.Show More ResponsesIf it isn't a binary search tree, then just traverse the tree in any which way and put the elements into a min heap. Then iteratively pop the min off the top to return smallest to greatest. Traversal would take O(n), building the min heap is also O(n), and popping min off n times is also O(n) so total is O(n).each popping takes logn. hence O(ologn)
4150 of 30,230 Interview Questions