# Senior Engineer Interview Questions

Senior engineer interview questions shared by candidates

## Top Interview Questions

### Senior Systems Engineer at Qualcomm was asked...

Given a wireless channel with loss rate 0.1, what's the throughput one can get with retransmission. 8 AnswersIt can modeled as binary symmetric channel. As to my understanding, channel capacity can be acheived with perfect feedback and simple retransmission scheme, so i guess the answer is 1-H(0.1). 10/(1.23456...)=8.1 packets per sec Interviewer was correct. With probability 0.1 you have one retransmission, with probability (0.1)^2 you have two, etc., since you can also lose the retransmitted packets, reducing the throughput to approximately 0.89. Show More Responses It is equivalent to simply a binary erasure channel with erasure probability 0.1, whose capacity is 1-0.1 = 0.9. aa should re-learn information theory and stochastic process First of all I don't think it has anything to do with the capacity of BSC. Note that h(0.1) = 0.46 and that means 1 - h(0.1) is roughly 0.5. If the packet error rate is 10% then BER is in the order of 0.1 / N where N is the length of the packet in bits. For that, the capacity of BSC is almost 1. In any case, in the non-ergodic case I believe the throughput is less than 0.9. Assume you want to send packets p_1, p_2, ..., p_k and each one takes N_1, N_2, ..., N_k time slots. Then, define the k-Packet Throughput (I made it up) as follows k-packet Throughput = (k / (N_1 + N_2 + ... + N_k)). Note that this throughput is a random variable. We can define the throughput based on this as the expected value of k-packet Throughput with respect to random variables N_1 , N_2, ... E[k-packet throughput] = E[ k / (N_1 + N_2 + ... +N_k)] 8' from the law of large numbers we have N_1 + N_2 + ... + N_k -> k E[N] = 1 / 0.9 * k. This suggests that k-packet throughput is a random variable which converges to its mean for large k, but for a finite k, its average is less than 0.9 All in all, I would have answered the question the way you did. In the long run, out of N transmissions you have 0.9 received and therefore the throughput should be 0.9 Model the problem based on the average number of transmissions it takes to deliver a packet. Let N be the number of transmissions. Then: Pr[N=1] = 0.9 Pr[N=2] = 0.1*0.9 Pr[N=3] = 0.1*0.1*0.9 ... and so on. The expected number of transmissions per packet is: E[N] = Sum{ k*Pr[N=k] } = 1*Pr[N=1] + 2*Pr[N=2] + 3*Pr[N=3] + ... where the summation index k goes from 1 to infinity. Then the throughput is 1/E[N] packets per transmission, which is 0.896... In the last solution, the number is calculated incorrectly. Accurate calculation gives the expected number of transmissions per packet E[N] = 1.11111, so that 1/E(N)=0.9, which corresponds to the reduction of transmission rate by exactly 10%, as suggested earlier. p=0.1 - probability of a packet transmission failure If we transmit a sequence of N packets with retransmission then an expected number of successfully transmitted packets will be E[N]=p*E[N-1]+(1-p)*(E[N-1]+1)=(1-p)+E[N-1], and as E[0]=0 it easy to solve the recursion: E[N]=N*(1-p) Expected number of successfully transmitted packets per one transmitted packet will be C[N]=E[N]/N=(1-p). The channel capacity is limit of C[N] as N approaching to infinity that is clearly equal to 1-p=0.9 |

Given and array. How do you find if there are such three numbers whose sum is Zero. What is the cost of this algorithm? 4 AnswersIterate over array using two nested loops, calculate sum of any possible combination of two numbers and store result in the set. Cardinality of this set would be n^2. Then, iterate over the array once again and check if for element e, we have -e in the set. Cost of this algorithm is O(n^2). The solution suggested by the Interview Candidate is not suitable to solve this problem. Consider the array contains [-6 3], if you use that solution, you will end up in the last phase of the algorithm checking if a 3 exists in the array, which resolved to true. However there are no three numbers in the array that sum to zero; we just considered 3 two times. One solution is to keep track of the numbers used in each case, but that's an additional O(2n) space complexity. I propose a more efficient solution in O(n^2) time complexity and O(1) space complexity. Let's first sort the array in O(n log n) using quicksort; that's in place sort so no additional space requirements. At this point, all elements are sorted in ascending order. for (int i = 0; i j) { int sum = arr[i] + arr[j] + arr[k]; if (sum == 0) { return true; } else if (sum < 0) { // We need a larger number j++; } else { // We need a smaller number k--; } } return false; } Correction: the return false should be moved after the last brace. Show More Responses shouldnt variable j be initialized to i+1? otherwise the first time sum is computed it uses arr[i] twice? |

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

Write a probability formula to tell how many bits will be changed when 1 is added to a 32 bit binary number. 10 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 Responses Using 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)) |

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

What will this program do ? ======== int main(void) { char *s = "123"; s[0] = 'a'; printf("%s", s); } ======== 4 AnswersIt will print a23 if you are lucky. Otherwise it will core dump since "123" is a constant (kept in the text area of your program I believe) and its contents should not be modified. It will not crash because it is not a constant. You can consider it as a pointer pointing to a modifiable 4-bytes char array. "123" is not a modifiable 4-byte array. It IS a constant and should not be modified. Try this out on different platforms and see what it does. Show More Responses C99 has a const qualifier to define constants. It makes no claims about whether the mentioned array is a non-modifiable array. If your platform crashes and burns on modifying the array then your platforms "c" implementation has an error. |

Describe a circuit that implements the following truth table using only NAND gates. A B OUT 0 0 1 0 1 1 1 0 0 1 1 1 6 Answers((A NAND B) NAND C) out = (A NAND (B NAND B)) out = ((A NAND A) NAND (A NAND A)) NAND (B NAND B) Show More Responses OUT = (A NAND (B NAND 1)) or out = (A NAND (B NAND B)) like what anonymous said. OUT = A' + B OUT = A' + B.1= A' + B.(A+A') = A'+ BA+ BA'= A'(1+B) + BA = A' +BA= (A.(BA)')' [Demorgans] = (A NAND(A NAND B)) out = A' & B' + A' & B + A & B; => A' & B' + B => (A' +B) & (B' +B) => A' + B => (A NAND (B NAND B)) |

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

Create a cache with fast look up that only stores the N most recently accessed items. 4 AnswersUse a hash map and a queue. I think you can do better than hash map and a queue...or just simply it. Since you're only interested in the N most recently accessed items, an array is suffice. Because N is essentially the index right? To ml: N was not the index, instead some random key. The combined data structure had the implement the interface: Object get(String key); and void put (String key, Object obj); Besides the array isn't the best choice when you have to take an object out of the array and add it to the front of the queue every time the object is accessed. A double linked list works better. The hash map entries points to an item in the linked list, which then points to the object to be returned. This way you can find the item quickly to move it to the front of the queue. Show More Responses This answer below has the best solution: http://stackoverflow.com/questions/1935777/c-design-how-to-cache-most-recent-used |

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

Print out, from small to big, of a sequence intergers, without sorting. 5 Answerspriority queue then The problem refers to dynamic programming, Longest increasing sequence in the given array. The time complexity of solution is o(n2). Add the sequence of integers to HashSet, which will apply natural order and then print the collection elements. Show More Responses If the integers are within a small range, then create an vector array, loop through all integers and flag the array. Then print out. Construct binary search tree and do inorder traversal. |

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

Write algorithm to compute a Log to the base 2 of a number (integral results no need for floating point). Solution should not assume a particular size of integer 5 Answersresult = 0 while(number != 1) { result++ number>>1 } return result // this c routine SHOULD compile and run ok regardless of sizeof (int) // It returns -1 for i<=0 as an error flag. otherwise it returns (int) log2(i) int l(int i){for(int j=0,k=1;k<=i;k<<=1,j++);return(j-1);} There are at least 2 bugs in the first proposed answer: "number >> 1" should be "number >>=1" Also, if initial value of number is 0 or less, this routine will infinite loop Likewise, the second solution only works for inputs less than 1/2 of maxint But I like it because it is concise :) Show More Responses public class Test2 { public static void main(String[] args) { System.out.println(new Test2().log(31)); // prints 4 } int log(int n) throws RuntimeException { if (n 0) { result++; n >>= 1; } return result; } } Binary numbers. The binary representation is in powers of two, like a logarithm. So. If you this "integer logarithm base-2" is the length of the binary representation of the number, minus one. def fast_log2(n): return len(bin(n)) - 3 Here I have to use "-3" instead of "-1" because Python's bin() function turns a number into a string with the prefix "0b". |

Given a grid of size m by n, write an algorithm that computes all paths from 0,0 to m,n such that you can always step horizontally or vertically but cannot reverse. 5 AnswersRecursion is the key here. Break the problem down into a base case and grow from there. atPoint (x,y, nrPaths): Output "we are at ", x, y if (x==width && y==height): return nrPaths+1; // we are at the other edge. if x<width: nrPaths = atPoint(x+1, y, nrPaths) if y<height: nrPaths = atPoint(x, y+1, nrPaths) return nrPaths There is also a way to calculate this with dynamic programming. You go from the m,n target backwards towards 0,0. each path can be represented as (m+n) bit binary number with m 0's (step down) and n 1's. Start with the minimal number (m most significant 0's and n least significant 1's), and transition to the maximum number (n most significant 1's and m least significant 0's). Each transition is achieved by replacing the right-most "01" pair with "10". Show More Responses import java.util.Iterator; import java.util.LinkedList; class Pair { private T x; private T y; public T getX() { return x; } public void setX(T x) { this.x = x; } public T getY() { return y; } public void setY(T y) { this.y = y; } public Pair(T x, T y) { super(); this.x = x; this.y = y; } public Pair() { super(); } public String toString() { return "{" + x + ", " + y + "}"; } } class Path implements Cloneable { private LinkedList> path; public Path() { super(); path = new LinkedList>(); } public void appendStop(int x, int y) { path.addLast(new Pair(x, y)); } public Pair getLastStop() { return path.getLast(); } public boolean isComplete(int lastX, int lastY) { Pair last = path.getLast(); if(last != null && last.getX() == lastX && last.getY() == lastY) { return true; } else { return false; } } public Path deepCopy() { Path copy = new Path(); copy.path.addAll(this.path); return copy; } public String toString() { return path.toString(); } } public class LinkedInAllPathsFrom00ToMNInAGridCanMoveHorizAndVertNotReverse { public LinkedList findAllPaths(int m, int n) { if(m incompPaths = new LinkedList(); incompPaths.add(start); LinkedList paths = findAllPaths(incompPaths, new LinkedList(), m, n); return paths; } private LinkedList findAllPaths(LinkedList incompletePaths, LinkedList completePaths, int m, int n) { while(incompletePaths.size() > 0) { Path currPath = incompletePaths.getFirst(); Pair lastStop = currPath.getLastStop(); incompletePaths.removeFirst(); //remove the current path from incompPath if it is complete, and add it to completePaths if(lastStop.getX() == m && lastStop.getY() == n) { completePaths.addLast(currPath); } else if(lastStop.getX() paths = l.findAllPaths(5, 8); Iterator itr = paths.iterator(); while(itr.hasNext()) { System.out.println(itr.next()); } } } Using mathematical "partitions". Get all the partitions on m and partitions on n. For each partition on m combine it with the partition of n that has the same number of terms. |

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

Write a program to reverse words in a string 4 Answers#include int main(int argc, char **argv) { int i; for(i = argc-1; i > 0 ; i--) { printf ("%s ", argv[i]); } printf ("\n"); return 0; } The above answer isn't correct, because it would reverse the order of the letters as well. For example: The quick brown fox => xof nworb kciuq ehT when it should be: fox brown quick The. You have to make another loop inside to traverse the length of each word, and then print that out in the correct order. in java, you can use string split. public class TestClass { public static void main(String[] args){ String str = "The quick fox jump over the dog"; String[] strs = str.split(str, ' '); String result = ""; for (int i = strs.length-1; i > 0; i--){ result += strs[i]; } System.out.println(result); } } Show More Responses public class TestClass{ public static void main(String[] args){ String str = "The quick fox jump over the dog"; String[] strs = str.split(" "); System.out.println("the output is: "); String result = ""; for (int i = strs.length-1; i >= 0; i--){ result = (result.length()>0?(result+" "):result)+strs[i]; } System.out.println(result); } } |

**31**–

**40**of

**7,485**Interview Questions

## See Interview Questions for Similar Jobs

- Systems Engineer
- Software Engineer
- Senior Software Engineer
- Engineer
- Director
- Project Manager
- Senior Engineer
- Principal Engineer
- Software Developer
- Manager
- Program Manager
- Systems Administrator
- Senior Manager
- Business Analyst
- Principal Systems Engineer
- System Engineer
- Solutions Architect
- Network Engineer
- Consultant
- Sales Engineer