# Computer Hardware & Software interview questions

## Interview Questions

An array of 99 elements contains integers from 1 to 100 with one missing element. Find the missing element. 22 Answers100 1. calculate the sum of elements in array say SUM 2. sum of numbers 1 to 100 is(n* (n+1))/2 = 5050 when n==100 3. missing element is (5050-SUM) 100 Show More Responses The parameters of the question do not allow you to determine what element is missing. Either more information should be supplied, or all answers are equally correct. How could an array size of 99 elements contain 1 - 100? Should either be integers 1-99 or 2-100 , in either case there is no missing element. All indices are accounted for. Sum them and then subtract them from 5050. In general, if an array of size n - 1 elements has unique elements from 1 to n, then the missing element can be found by subtracting the sum of the elements in the array from sum(1 ... n) = n * (n + 1) / 2. Alternately, one could use a boolean array of length n with all values set to false and then for each value, set array[val - 1] to true. To find the missing value, scan through the array and find the index which is set to false. Return index + 1. This requires O(n) memory and two passes over an O(n) array (instead of constant memory and one pass), but has the advantage of actually allowing you to verify whether or not the input was well formed. Admittedly, this question is poorly posed; however, the answer they are looking for refers to the syntax/nomenclature of some (not all) programming languages to index arrays starting at “0.” As such the 1-100 stored values would be in entries 0-99 of the array. Read the question. Here are the steps to solve it: 1) find the sum of integers 1 to 100 2) subtract the sum of the 99 members of your set 3) the result is your missing element! Very satisfying! Sort array. While loop with an index variable with condition of next element being 1 greater than previous element. When loop breaks, return the value of the index. Doing the expected sum and subtracting the actual gives the run time of O(2n), however a bucket sort will almost always do it in less time (somewhere between O(n) and O(2n)): 1. create a 101-int (or boolean) array (to have a 100-index) 2. traverse original and for each int, assign value in bucket array to 1 or true. 3.After first traversal, traverse created array starting at one, and when value is false, print it. 100 100 coz in array it initial value starts frm 0 to 100. or else 4 further clarification u can study array chapter in c or c++ 100 Show More Responses The question: "An array of 99 elements contains integers from 1 to 100 with one missing element. Find the missing element." The information states that the integer count is 1 to 100. I take this to be inclusive of all elements in the array so that the missing inters would be subjective to their arrangement or random. In other words, I do not have enough information to say which one. 1 I need more information. 1. Are the integers unique in this array? 2. Do I have enough information to find the sum of the integers in the array (or some aggregation)? If sum is available, then, the answer is 5050-sum{integers}. Bucket Sort works and summation works. I think both are good, practical and clever solutions. I think sorting the array then searching may be unnecessary computation. Another interesting method which may be faster. SIMD computers may do this particularly quickly: Do a bitwise operation on all the elements: Result = Array[0] xor Array[1] xor ... Array[98] xor 1 xor 2 xor ... xor 100 Result = Missing number. Explanation: When you xor 2 identical numbers your result = 0. For example, 5 xor 5 -> 101 xor 101 = 000. (5 in decimal is 101 in binary). Knowing that "xoring" 2 identical numbers results in zero is useful. Now we apply this useful info to the problem. Array is Identical to a list of 1,2,3,...,100 except for one number. In other words 1,2,3,...,100 duplicates all of array's elements and adds one extra element that is missing in Array. Therefore, we now have 2 instances of each element in the Array in addition to one extra element in 1,2,3,...,100. We can see when you xor two duplicate numbers you get zero. Because we have pairs for all numbers in Array and one extra number we are essentially "xoring" the missing number with zero. When we xor the missing number with zero we get the missing number. (For example, 6 xor 0 -> 110 xor 000 = 110) The question states that one (not two or three or n) element ("value") from 1 to 100 is missing. There are 99 elements ("values") in the array. The question implies that the data is well-formed because it states that only element is missing. It doesn't ask you to find the missing value(s), but the one (singular) missing element. With the problem constrained, the solution falls out. Subtracting from 5050 is an elegant solution, but not obvious as to why it works. The array of booleans is more obvious, but doesn't scale well. I agree with one of the answers in this thread...5050-sum(elements) = missing item. Other approach that crossed my mind is something similar to binary search. Check the index of 50th element: if A(50) == 50, the missing element > 50, else if A(50) > 50, missing element <50. Do this iteratively. The number of comparisons would be log 100 = 7. 0 100 Add 1-100 to a hash of 100 elements. Then compare each element with the hash.. Answer in o(n) |

How do you convince a CIO of a utility to care about energy efficiency? 5 AnswersThis is a bit of a trick question. CIO really does NOT care about efficiency because it means less revenue. However, some states are mandating efficiency programs and so the CIO wants to do this as cost effectively as possible. Some utilities in some states also face competition for energy consumption, so a customer engagement program that makes consumers feel good about their utility will help with rate approvals and satisfaction ratings, which will boost the bottom line overall. He cares because if he can lower the system peak number, he can lesson the amount of spinning reserves he must have in place, whixh in effect is stranded capital. CIO cares since as a company executive he needs to work with his customers (operating unit executives) to cut costs and increase revenues. By providing a solution that mines data to assist customer to save energry usage - the CIO is prioviding a solution for the utility to flatten its energy demand curve. Show More Responses CIO at a utility does not buy this product, nor would she/he care about this. Not their lane. Simple. You demonstrate a cost savings analysis comparing efficient energy use to inefficient energy use. Use a graph of the inefficient use, compare to an efficient use, then run assign the value. That is just one way. This of course assumes that the inefficient use cost more then the cost to correct the problem. But if you do make the changes you can leverage the changes into a PR piece and get a double benefit (efficient use and a "look at us going green!" piece.) |

In a given sorted array of integers remove all the duplicates. 6 AnswersIterate the array and add each number to a set, if number is already there, it won't be added again, thus removing any duplicates. Complexity is Big-O of N The array is already sorted, no need for a set. example: 2,2,5,7,7,8,9 Just keep tracking the current and previous and the index of the last none repeated element when found a difference copy the element to the last none repeated index + one and update current and previous, no extra space and it will run in O(n) public RemoveDuplicates() { int[] ip = { 1, 2, 2, 4, 5, 5, 8, 9, 10, 11, 11, 12 }; int[] op = new int[ip.Length - 1]; int j = 0, i = 0; ; for (i = 1; i <= ip.Length - 1; i++) { if (ip[i - 1] != ip[i]) { op[j] = ip[i - 1]; j++; } } if (ip[ip.Length - 1] != ip[ip.Length - 2]) op[j] = ip[ip.Length - 1]; int xxx = 0; } Show More Responses def removeDuplicatesSecondApproach(inputArray): prev = 0 noRepeatIndex = 0 counter = 0 for curr in range(1,len(inputArray)): if (inputArray[curr] == inputArray[prev]): counter = counter + 1 prev = curr else: inputArray[noRepeatIndex+1] = inputArray[curr] noRepeatIndex = noRepeatIndex + 1 prev = curr inputArray = inputArray[:-counter] return inputArray if(inpArr[i] == inpArr[i+1]) { int repeats = 1; opArr[opPos] = inpArr[i]; int j = i + 1; while(j+1 <= inpArr.length - 1 && inpArr[i] == inpArr[j+1]) { j++; repeats++; } opArr = Arrays.copyOf(opArr, opArr.length - repeats); i = i + repeats; } else { opArr[opPos] = inpArr[i]; } opPos++; } for(int i =0; i<=opArr.length-1;i++) { System.out.println(opArr[i] + ","); } Apologies for the previous incomplete answer int[] inpArr = {1,2,2,3,4,5,5,5,8,8,8,9,13,14,15,18,20,20}; int[] opArr = new int[inpArr.length]; int opPos = 0; for(int i= 0; i<=inpArr.length - 1; i++) { if(inpArr[i] == inpArr[i+1]) { int repeats = 1; opArr[opPos] = inpArr[i]; int j = i + 1; while(j+1 <= inpArr.length - 1 && inpArr[i] == inpArr[j+1]) { j++; repeats++; } opArr = Arrays.copyOf(opArr, opArr.length - repeats); i = i + repeats; } else { opArr[opPos] = inpArr[i]; } opPos++; } for(int i =0; i<=opArr.length-1;i++) { System.out.println(opArr[i] + ","); } |

how can a particular application be tested apart from testing its functionality 3 AnswersReliability Test, Stability Test, UI Test, Platform Test, Also include, performance, stress & load testing Accessibility, user experience, globalization, localization, integration, compatibility |

### National Account Manager at NCR was asked...

Describe a sales situation where price seemed to be the primary driver and how you overcame the focus on cost and made it more about 'value.' 2 AnswersI focused on the benefits of the product and the additional service that is provided to support them. While we are large enough to give the bast deal we are also small enough to give great customer service. |

What would I do to improve and ensure product quality if given the job? 2 AnswersFirst thing, get acclimated and learn and understand the status quo (what development processes and tools are currently being used, what ideas/feedback internal stakeholders have about the current state of things, what comments/feedback have our customers provided, etc). These are all important because before you can set out to improve something you must first understand what it is that needs improved - and why - and how - and by whom, etc. It's nice to have an improvement plan in mind but it's more important to recognize and understand there's no such thing as a 'one size fits all' plan. Seeking to implement change w/o first seeking to understand what needs to be changed and why is basically just change for change's sake - not a good thing. The forst rule to improve the quality should be to see if we are meeting to "confirm" the basic requirement set by the customer or not. If we have 100 processes going on, but the confirmance to requirement is stil not met, we really have a huge job to do. So first do a gap analysis quickly that how far we are from actually meeting the requirement of the client, Once we fill that gap, we need to see how can we now "delight" the client. |

### Systems Engineer at Symantec was asked...

can you host multiple https sites with different domain names but same IP on the same server? how 3 AnswersNO, server cant tell which site is which because traffic is encrypted. The way question posed, the answer is YES, since you could cover all those https sites with a single certificate. But now this should even work for individual certificates http://en.wikipedia.org/wiki/Server_Name_Indication Yes you can that's what virtual hosting is for. https://en.wikipedia.org/wiki/Virtual_hosting |

How do you influence people who do not report to you? How do you get them to do things even though they don't have to or want to? 2 Answersa) I've never actually had someone refuse to help me when asked, but b) I would try ahead of time to get to know them so that when I need to influence them or need to request assistance, they already have a basic level of comfort with me. I would answer this question by first stating that it is important to get to know how people are motivated on a personal level first. If they do not report to you then you might not have positional authority to ask them for a deliverable. At a company like Microsoft, I'm sure that there are jobs/roles that require people to get help/collaboration from people outside of their positional authority. To do this, you must first know what motivates a person and proactively make personal "deposits" to build some solid connections so that when you need to make a "withdraw" you have invested enough. Deposits can be made by taking an interest in someone, providing them with help when they need it, or maybe buying them lunch/drinks. |

What is a JavaScript callback function? 4 Answers5 vote down star 4 I understand passing in a function to another function as a callback and having it execute, but I'm not understanding the best implementation to do that. I'm looking for a very basic example, like this: var myCallBackExample = { myFirstFunction : function( param1, param2, callback ) { // Do something with param1 and param2. if ( arguments.length == 3 ) { // Execute callback function. // What is the "best" way to do this? } }, mySecondFunction : function() { myFirstFunction( false, true, function() { // When this anonymous function is called, execute it. }); } }; In myFirstFunction, if I do return new callback(), then it works and executes the anonymous function, but that doesn't seem like the correct approach to me. I don't think Bloomberg is a very good company. I am an excellent web developer and have gotten multiple offers from other companies with big names, but was rejected by Bloomberg. They are too demanding during the job interview and it becomes a game of how well you can interview as opposed to how talented an employee you are and how much you can contribute to the growth of the company. A callback function is a piece of JavaScript code that executes after the main function that the callback is attached to executes successfully. Show More Responses udaykanth, I would say that a .forEach() would be the most common and most basic use of a callback function. I'm just writing this to help anyone that might have a hard time thinking up a quick example if the come across this question themselves. Example: var numArray = [ 1, 2, 3 ] ; numArray.forEach( function( i ) { console.log( arr[ i - 1 ] ) } ) ; // logs out // 1 // 2 // 3 |

### Sales Representative at Salesforce was asked...

What salesforce product would you sell and how would you sell it? 3 AnswersLearn as much as you can about their products Hi - how did you create a preso? Did you have something to work off of as a template? I have to beieve it would be hard to present a product you have never sold before. Be well-versed in their products and services so that you can give a persuasive sales pitch. Make sure to be aware of any faults, weaknesses, or common concerns so that you can counter these effectively. |