# 73K

senior engineer interview questions shared by candidates

## Top Interview Questions

Sort: Relevance|Popular|Date
Senior Software Engineer was asked...13 July 2009

### Given an array of numbers, replace each number with the product of all the numbers in the array except the number itself *without* using division.

It seems to me that for any number array[i], you're looking for PRODUCT(all array[j] where j i]) we can simply precompute these "running products" first from left-to-right, then right-to-left, storing the results in arrays. So, leftProduct[0] = array[0]; for j=1; j = 0; j-- rightProduct[j] = rightProduct[j+1]*array[j]; then to get our answer we just overwrite the original array with the desired product array[0] = rightProduct[1]; array[n-1] = leftProduct[n-2]; for j=1; j &lt; n-1; j++ array[j] = leftProduct[j-1] * rightProduct[j+1] and clearly this solution is O(n) since we just traversed the data 3 times and did a constant amount of work for each cell. Less

betterStill, I think you have the answer the interviewer wanted.. But... if the array is google sized, don't we have to worry about overflows? Less

narya trick is good but really useful as it might take more iterations depending on values... eg. 2,3,1000000000000000 so if you have 3 numbers and if you are trying for the first one it will go for 500000000000000 iterations, hence as the overall product value wrt to the value matters a lot... try something else.... Less

### Coderpad: given an array scores[][] = {“jerry”,”65”},{“bob”,”91”}, {“jerry”,”23”}, {“Eric”,”83”}} Find the student with highest average score

package Hello; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import static java.util.Comparator.comparingInt; public class hello { public static class Average { public int count; public int num; public int average; public Average(int count, int num, int average) { super(); this.count = count; this.num = num; this.average = average; } public Average() { super(); } } public static void main(String[] args) { String s[][] = {{"jerry","65"}, {"bob","91"}, {"jerry","23"}, {"Eric","83"}, {"bob","10"}}; Map map = new HashMap(); int avera = 0; try { for(String x[]:s) { if(map.containsKey(x[0])) { Average avg = map.get(x[0]); int val = avg.num + Integer.parseInt(x[1]); int count = ++avg.count; int average = val/count; map.put(x[0], new Average(count, val , average)); } else { if(x[0] != null) { int val = Integer.parseInt(x[1]); map.put(x[0], new Average(1, val, val )); } } } avera = map.entrySet() .stream() .max(comparingInt(e -&gt; e.getValue().average)).get().getValue().average; } catch(Exception e) { } System.out.println(avera); } } Less

Can anybody please tell, If anything is wrong with this simple approach : public class StudentWithMax { private static class Student { public String name; public Double avg; Student(String n, Double a) { name = n; avg = a; } } public static void main(String[] args) { String[][] s = { { "Jerry", "65" }, { "Bob", "92" }, { "Jerry", "33" }, { "Eric", "83" }, }; Student maxStudent= new Student("", (double)Integer.MIN_VALUE); for (String[] strings : s) { //System.out.println(strings[0]); if(Double.parseDouble(strings[1]) &gt; maxStudent.avg) { maxStudent.name=strings[0]; maxStudent.avg=Double.parseDouble(strings[1]); } } System.out.println("name: "+maxStudent.name + ", avg: " + maxStudent.avg); } } Less

Solving same problem using Java 8: import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; public class MaxScore { public static String s[][] = {{"jerry","65"}, {"bob","91"}, {"jerry","23"}, {"Eric","83"}}; public static void main(String[] args) { List arrayOfLists = Arrays.asList(s); List students = arrayOfLists.stream().map(s-&gt;new Student(s)).collect(Collectors.toList()); Optional studentWithMaxScore = students.stream().max(Comparator.comparing(Student::getScore)); System.out.println(studentWithMaxScore.get().getScore()); } } class Student{ private final String name; private final int score; public Student(String[] s) { String name = s[0]; String score = s[1]; this.name = name; if(score.matches("-?\\d+(\\.\\d+)?")) { this.score = Integer.parseInt(score); } else { this.score = 0; } } public String getName() { return name; } public int getScore() { return score; } } Less

### Draw a bridge and you have three people trying to cross? Seriously&amp;gt;

I actually had an interview with Clearleap yesterday and I can tell you that above comments are not true. Interview process was very professional. Problem solving questions were quite interesting and I enjoyed them! Less

Unfortunately, your response is quite immature and therefore I withdraw myself from this conversation. Less

4 people actually (you missed the requirement). Looks like you did not pay attention during the interview. These types of questions are designed to figure out your: a) Problem solving skills b) Creativity c) Ability to work under pressure And most of all to observe your thought process. But in your Senior QA Engineer role you should have know about that already, right? Less

### Consider an X x Y array of 1's and 0s. The X axis represents "influences" meaning that X influences Y. So, for example, if \$array[3,7] is 1 that means that 3 influences 7. An "influencer" is someone who influences every other person, but is not influenced by any other member. Given such an array, write a function to determine whether or not an "influencer" exists in the array.

public static int influencer(final int[][] jobs, final int r, final int c) { int[] degree_in = new int[jobs.length]; int[] degree_out = new int[jobs.length]; for (int i = 0; i &lt; r; ++i) { for (int j = 0; j &lt; c; ++j) { if(jobs[i][j] == 1) { // i influences j degree_out[i]++; degree_in[j]++; } } } for (int i = 0; i &lt; r; ++i) { if (degree_out[i] == r - 1 &amp;&amp; degree_in[i] == 0) { return i; } } return -1; } Less

//if vec[i][j] == 0 then i is not an influence //if vec[i][j] == 1 then j is not an influence //so time complexity is O(n) bool find_influences(vector &gt; &amp;vec) { int n = vec.size(); vector not_influence(n); for (int i = 0; i = 0; --j) { if (!vec[i][j]) { break; } not_influence[j] = 1; } if (j &lt; 0) { return true; } } not_influence[i] = 1; } return false; } Less

X should be equal to Y, right?

### Write some pseudo code to raise a number to a power.

int raise(num, power){ if(power==0) return 1; if(power==1) return num; return(raise(num, power-1)*num); } Less

small mistake function power(x, n) { if n == 1 return x; // Even numbers else if (n%2 == 0) return square( power (x, n/2)); // Odd numbers else return power(x, n-1) * x; } Less

double Power(int x, int y) { double ret = 1; double power = x; while (y &gt; 0) { if (y &amp; 1) { ret *= power; } power *= power; y &gt;&gt;= 1; } return ret; } Less

### Write a probability formula to tell how many bits will be changed when 1 is added to a 32 bit binary number.

The 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. Less

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. Less

@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. Less

### How many credit cards does Amex issue in a year in US?

Do you remember what type of questions they asked in online coding screen sharing ? I have an interview on next tuesday and i am nervous about typing code in a text editor . Can you give me some sample questions they asked ? Less

These were fairly straight forward ones- FizzBuzz, Fibonacci for coding problems, couple of bitwise operations with XOR, regex for US phone number, abt 50% theory questions like interface vs abstract classes and uses of generics and SOLID principles. One question were I messed up a bit was 'Write the api for System.out.println()'. I didn't fully understand the question, then the interviewer clarified. Essentially, he wanted me to write the classes and methods (ignoring the actual logic code) that would allow the user to write System.out.println(). I used inner class to implement it. Good luck. Less

Thanks. I was contacted by the Sr.Director about 10 days after the interview and made the offer. Less

### In a stream of integers from 1 to n, only one number will be repeated. How can you tell what that number is?

You know n. S = n*(n+1)/2 is the sum of 1st n numbers. P = sum of the n+1 numbers you are provided with. Finding P given an array of n+1 integers can be done in O(n). P - S is the repeated integer. Less

If you're writing it in ruby def find_repeat(numbers) numbers.length.times{|n| return numbers[n] if numbers[n] != n } end Less

Mat, try 1,2,2,3: 1+2+2+3= 8 1^2^2^3= 2 (8-2)/2=3?2

### Create a stack of numbers where the maximum number is always known.

To Job Seeker: The basic idea is that when a new number is being pushed onto the stack, you need to see if that number is greater than or equal to the current top of the maximums-stack. If it is, you push the number onto maximums-stack as well. Also, when pop is called, you look to see if the number being popped is equal to the number on the top of the maximums-stack. If it it, pop that stack as well. Less

sorry, typo while(top&gt;p)

I was asked of this question as well. I not sure how to implment a second stack in a way that the max number is always on top. Less