Software Engineer Interview Questions in San Jose, CA | Glassdoor

# Software Engineer Interview Questions in San Jose, CA

Software engineers write programs to design and develop computer software. Interviews are highly technical, so come ready to work through coding problems and math brainteasers. The specific questions you are asked will depend on what type of programming position you are looking for. Try researching a specific software discipline such as web development, application development, or system development.

## Top Interview Questions

Sort: RelevancePopular Date

### Software Engineer at Ooyala was asked...

Dec 16, 2010
 Given two integer arrays. Find the Largest Common sub array. For example, arr1 = {1,2,3,2,3,2} arr2={2,2,3,3,4,5}, the largest common sub array is {2,2,3,3}8 AnswersI try to an array as a hash table. index is the element, value is the times the element appears in arr1, and then traversal arr2, with the hash table. The problem of my algorithm is that I need to know the range of the arrays' element value, because I need to use that to define the size of my array. The interview asked me if I was familiar with the STL hashmap, which i was notWas this asked in phone interview ?sort + join - looks like the answerShow More ResponsesThe question is confusing.You are sayin common sub array but the sub array is present only in 2nd array.common sub array should be {2,3} instead of {2,2,3,3}it seems from the answer that the question is actually the longest common subsequence, which is a dynamic programing problemthis has several answers but no need for dynamic programming solution. 1. sort + join - O(nlogn) 2. keep counts for integers in array or hashmap - O(n) but need lot of extra space O(n)Seems the question is to give an array with the common elements between the two arrays. If this is the case, you should use a HashMap. The keys are numbers in the first array. The value is the number of times each one shows up. Have an array for the result. Then go over the second array. Look for each number in the hashMap. If it's there and the value is greater than 0, append it to the result and reduce in 1 the value in the hashmap for that number. public static Integer [] commonElements ( int [] a, int [] b ){ java.util.HashMap h = new java.util.HashMap (); for ( int e: a ){ if (h.containsKey(e))h.put(e, h.get(e)+1); else h.put(e, 1); } java.util.ArrayList resultAL = new java.util.ArrayList (); for ( int e: b){ if ( h.containsKey(e)&&h.get(e)>0){ resultAL.add(e); h.put(e, h.get(e)-1); } } Integer[] result = resultAL.toArray(new Integer [ 0 ]); return result; }

### Software Engineer Intern at eBay was asked...

Jan 19, 2011
 Questions related to data structures like "What data structure would you use for a browser's BACK & FORWARD ability"6 AnswersMay be Stack , any one please correct me if I am wrong.This can be implemented by using two different stacks, one for back and one for forward.Command PatternShow More ResponsesI would use doubly link listDoubly linkedListUse two stacks. Every time you visit a site, push its address in stack1. When you press back, pop from stack1 and also push in stack2. When user presses forward, pop from stack2 and also push in stack1.

### Software Engineer at Facebook was asked...

Oct 1, 2010
 Given a matrix print it clockwise from the first element to the very inner element.6 AnswersNeed to design the program first and then implement it very carefully yet fast!void PrintMatrix(int** a, int n) { for (int i = 0; i = i; j--) { printf("%d ", a[n - i -1][j]); } } void PrintColInc(int** a, int n, int i) { for (int j = i; j = i; j--) { printf("%d ", a[j][i]); } }struct point { point(int a, int b) { row = a; col = b; } int row; int col; }; void printMatrixSpiral(int a[], int r, int c) { int direction = 1; // 1 - right // 2 - down // 3 - left // 4 - up point upper_left = point(0,0); //point upper_right = point(0,c-1); point lower_right = point(r-1, c-1); //point lower_bottom = point(r-1, 0); while(true){ if(direction==1){ int row = upper_left.row; for(int i=upper_left.col; i= upper_left.col;--i){ cout= upper_left.row;--i){ cout lower_right.row) || (upper_left.col > lower_right.col)){break;} } }Show More Responsesint matrix[] = { {1, 2, 3}, { 4, 5, 6}, {7, 8, 9} }; void PrintMatrix() { int start = 0; int end = 2; while(end >= start) { for(int col = start; col = start; col--) cout start; row--) cout << matrix[row][start] << " "; start++; end--; } }int main() { int m, n; cin >> m >> n; int matrix[m][n]; for (int i = 0; i > matrix[i][j]; int l = 0, r = n, t = 0, b = m; while (l = l; i--) cout = t; i--) cout << matrix[i][l] << ' '; l++; } return 0; }^ Above anon, your solution is almost correct. But for the 3rd and 4th for loops you first need to check whether you've already printed the corresponding previous for loop. Ok I didn't explain that too clearly. Here's an example: Matrix: {{1,2,3,4},{5,6,7,8},{9,10,11,12}} will print 1 2 3 4 8 12 11 10 9 5 6 7 6 That last 6 is because of the 3rd for-loop. You don't need to run that opposite for-loop (R-L) once you've already printed 6 from L-R. Just use an if-loop to rectify this. Same for the 4th loop.

### Software Engineer Intern at PayPal was asked...

Apr 25, 2012
 n= 20 for (i=0;i

### Software Engineer at PayPal was asked...

Dec 18, 2011
 CODING (weight: 50%) The string "PAYPAL IS HIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: PAHNAPLSIIGYIR Write the code that will take a string and make this conversion given a number of rows: String convert(String text, int nRows); convert("paypalishiring", 3) should return "pahnaplsiigyir" 6 Answersstatic String convert(String sentence, int numberOfRows) { char[] arr = sentence.toCharArray(); String ret = ""; if(numberOfRows == 1) return sentence; int repeatPattern = numberOfRows + (numberOfRows - 2); for(int i = 0; i < numberOfRows; i++){ int s = i; do{ ret += String.valueOf(arr[s]); if(i < numberOfRows - 1 ) { s = s + repeatPattern; } else s = s + numberOfRows + (numberOfRows - 2); }while(s < arr.length); repeatPattern -= 2; } return ret; }void convert(String s,int r){ int len=s.length(); ArrayList> allLine=new ArrayList>(); for(int i=0;i line=new ArrayList(); allLine.add(line);} int row=0,i=0; while(i0 && istatic String convert_al(String text, int nRows) { char [] char_array = text.toCharArray(); StringBuffer []array = new StringBuffer[nRows]; for(int i=0;i0 && iShow More Responsespublic static StringBuilder strConversion(String in,int rows) { StringBuilder[] stb=new StringBuilder[rows]; StringBuilder out=new StringBuilder(); int index=0; int i=0; for(int j=0;jstring convert(const string& input, int rowCount) { if ((input.length() == 0) || (rowCount > arrStrings; arrStrings.resize(rowCount); vector &currArray = arrStrings; currArray.push_back(input.substr(0, 1)); for (int idx = 1; idx &currArray = arrStrings[rowIdx]; currArray.push_back(input.substr(idx, 1)); } for (int rowIdx = rowCount - 2; rowIdx >= 0 && idx &currArray = arrStrings[rowIdx]; currArray.push_back(input.substr(idx, 1)); } } string strTemp; for (size_t idx = 0; idx &currArray = arrStrings[idx]; for (size_t j = 0; j < currArray.size(); j++) { cout << currArray[j] << " "; strTemp += currArray[j]; } cout << endl; } return strTemp; }package com.learn; public class ZIGZAGPattern { public static void main(String[] args) { ZIGZAGPattern pattern = new ZIGZAGPattern(); System.out.println(pattern.strConvertToZigZag("PAYPALISHIRING",3)); } public String strConvertToZigZag(String str, int rows) { StringBuffer []sb = new StringBuffer[rows]; StringBuffer finalsb = new StringBuffer(); for(int i=0;i0 && count

### Senior Software Engineer at Google was asked...

Jan 2, 2014
 Write a probability formula to tell how many bits will be changed when 1 is added to a 32 bit binary number.11 AnswersThe probability of N bits being changed is (1/2)^N. The reason: the number of bits that will change depends on the position of the first zero that appears in the number. If the first zero is at the LSB, only one bit changes; if it is in the third position, the three bits upto the first zero change. Now, it boils down to the probability of finding the first zero. Assuming that the zeros and ones appear with equal probability in a given number, the probability of finding the first 0 in the Nth position is (1/2)^N. For more, look up the Geometric Random Variable.I think that you need to take into account that if you want to toggle 2 bits, you can only do if you flip bits from position 0..30. Toggling bit 31 is only going to toggle this bit no matter what. Therefore, you need to multiply (33-N)/32 to your proposed result, to keep this into account.@Mythreya's analysis is correct but incomplete. To get the expected value, you have to multiply the number of bits by their probability. Answer is Sigma{k/(2^k)} for k = 1 to 32.Show More ResponsesUsing this approach, the answer is 2 bits will change on an average: https://answers.yahoo.com/question/index?qid=20110413165236AAU9tmO@Henry David Thoreau: The question is not asking for expected value, just the discrete density function. Also P(k=32) needs special handling.@Henry, no ... probability that at least 1 bit will change is (k/2^k); but, probability for all k bits to change, I guess, would still be 1/2^k. Right?And, k=0 to 31 !!k=1-32 p=k/2^(k-1)E(n) = 1 + E(n-1) / 2 where E(n) is the expected number of bit changes when 1 is added to an n-bit integer. E(1) = 1. E(2) = 1 + E(1) / 2 = 1.5. E(3) = 1 + E(2) / 2 = 1.75 We can verify it for n = 3. The possible values are as follows 000 -> 1 change 001 -> 2 change 010 -> 1 change 011-> 3 change 100-> 1 change 101-> 2 change 110-> 1 change 111-> 3 change Total changes: 14 Expected change = 14 / 8 = 1.75;answer is (2^1+2^2+2^3....2^32)/(32*(2^32))If we just look at two bits - (b1,b2) f(b1) = { 1 b1=0; f(b2) if b1=1}, the probability of one bit changing is half. The probability of two bits changing is half * f(b2), which is half*half if b2=0 and half*half*f(b3) if b2=1. Therefore, for k=1-31 p(k) = 1/2^k and for p(k=32) = 1/2^k because when the 32nd bit flips there is nothing more to be done and the recursion stops

### Software Engineer at PayPal was asked...

Nov 10, 2011
 Consider the following function: int f (int num) { int out = 0; for (; num > 0; num /= 10) { int d = num % 10; out *= 10; out += d; } return out; } 1) What does it do? 2) Write the same algorithm using recursion5 AnswersThere is a trick that need global variable or static variable to record the temper sum. so the function declaration cannot be same as loop version if don't use global or static variable. the output parameter b will be the reverse result. void rev(int d, int& b) { b *= 10; if (d/10 == 0) b += d; else { b += d%10; rev(d/10, b); } }You can do it without the golbal or static variables: int f(int num) { if((num/10) == 0) return num; else return ( 10(num%10) + f(num/10) ); }Sorry my answer previously posted was wrong. Here is the correct one without golbal or static variables, which is basically the same as the first one by Paul. inf f(int num, int car=0) { car *=10; if((num/10) == 0) return ( car + num ); else return f(num/10, car+(num%10) ); }Show More Responsesprivate static int reverse(int n, int r) { if (n == 0) return r; return reverse(n/10, 10*r+n%10); } public static int reverse(int n) { return reverse(n, 0); }Simple method without using global variable. static int reverseRecursive(int number, int sum) { if (number != 0) { int temp = number % 10; sum = sum * 10 + temp; return reverseRecursive((number / 10), sum); } else return sum; }

### Software Engineer Intern at eBay was asked...

May 17, 2012
 Assuming a preexisting list of 100 words, how would you efficiently see if a word received from input is an anagram of any of the 100 words?4 AnswersFirst Sort 100 words and keep the hash of sorted words.. Now when you recieve a word, SOrt it and check if Hash contains that key. O(nlogn) Where n is length of String.Hi I think you can take a look at the most efficient algorithm for this question in this link www.crackeasily.com/2012/01/find-whether-2-strings-are-anagrams.htmlTo say what MW said more clearly: If you sort words that are the same anagram they will always look the same. Example: "god" and "dog" both look like "dgo". So you sort the input word, then you iterate through the list of 100 words, and while looking at each word sort that word. compare if the input and that word are the same. If they are then you have found an anagram. if you made it to the end of the list and you haven't found an anagram then an anagram does not exist in the list.Show More ResponsesSorting takes O(nLogn) average time. This can be further improved by counting characters in the strings. So, for the given string calculate count of each character in an array . For each word in the list, check if it contains the same count for its characters and return that word. Complexity O(n)

### Intern - Software Engineer - Cisco Choice at Cisco Systems was asked...

Apr 5, 2012
 Write a program to reverse a string3 AnswersString reverse(String s){ int length = s.length()-1 String s1 = "" while (length >= 0){ s1 = s1 + s[length] length-- } return s1 }forget semicolumns (;), sorryPush char by char on a stack then concatenate all the pops until the stack is empty.

### Software Engineer Intern at eBay was asked...

Mar 3, 2014
 How to retrieve a file with a specific string or keyword using UNIX command line3 AnswersI knew it had some thing to do with grep but was unable to give the specific line.grep -r "expression to find"find . | grep -i "String" find is generally used to find the name of the files & Grep is used to search for content present in the file
110 of 1,516 Interview Questions