Questions d'entretiens - Software | Glassdoor.ca

# Questions d'entretiens - Software

5,951

Questions d'entretien de Software partagées par les candidats

## Le top des questions d'entretien

Trier: PertinencePopulaires Date

### Cette question a été posée à un(e) Software Engineer chez Facebook :

3 nov. 2012
 implement sqrt without using math libray9 réponsese^((ln(x))/2)I think exp and ln still require a Math library. How about using Newton's method to find the root of f(x) = x^2 - a, where x is the solution (the sought square root) and where a is the number for which you want to find the square root?I would have implemented either Taylor or MacLaurin series, centered at an integer number that is closest to the number that you want to find the square root for, such that the square root of this integer is clean. So if you wanted to find the square root of 8.5, I would centre the series at 9 (sqrt(9) = 3), then compute the series at that point. I'd probably choose between 8 and 10 terms, as that is what is used in any scientific calculator.Afficher plus de réponsesActually, to add to that, I wouldn't be able to include 8 - 10 terms, as that would rely on the square root operation itself.... so I'd have to rely on a linear approximation.This is the way to go. Fast inverse square root as used in Quake III. float Q_rsqrt( float number ) { long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = * ( long * ) &y; // evil floating point bit level hacking i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = * ( float * ) &i; y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed return y; }For detailed explanation of the algorithm, see http://en.wikipedia.org/wiki/Fast_inverse_square_rootI wouldn't know about this algorithm, but I can think of a (definitely slower than this one) bisection algorithm to find the root of x^2 = number.Often what they are looking for is a programming data structures oriented solution. Such as using binary search to find sq root etc.poop

### Cette question a été posée à un(e) Intermediate Software Developer chez The PEER Group :

19 mars 2009
 Your on a farm, and your in a field with horses and you have a fence that you have to repair. But you left your hammer back at the house, what do you do? Remember the fence is broken and you cannot leave it alone otherwise the horses will escape.7 réponsesRide one horse back to the house to get your hammer and use rope to temporarily secure the fence. or Tie one horse to the fence and go back to the house and get your hammer.Take a belt, if you have one, and tie the fence until you go home for the hammer.Why do you need a hammer to fix the fence? Maybe that assumption needs to be questioned. How is this for an assumption? Since its a farm, chances are the fence is made up of 5-6 ft. long wood pieces; which can be maneuvered into poles by hand. So, I would fix the fence and be on my way.Afficher plus de réponsesGrab a rock and use it as a hammer. IMO a hammer is the easiest tool possible to replace.If there's absolutely no way to repair the fence without the hammer (can't use your shoe), and you have no assistant, bring the horse(s) with you to the house. Or send them into the barn -- pretty much all horses have a shelter for inclement weather, after all. Or scare all the horses to the far end of the pasture, then tie your shirt to the broken fence piece so it waves in the wind and spooks the horses away. Then go get the hammer. But frankly, if the fence is broken, how come the horses didn't escape before you got there to notice it was busted?Why assume the horses will want to leave? Horses are herd animals. Secure the stallion or lead mare, the rest will stay with them. How did it get broken while the horses were there, anyway? Are any of them injured? Do you have a bigger problem than some loose rails? Who left the horses in a pasture with a broken fence? If it was you, how will you CYA? If it was a coworker, how will you handle it? If it was the farmer's pretty daughter... nevermind.Or maybe just call someone to send over the hammer because the question does not say that I do not have a phone.

### Cette question a été posée à un(e) Software Engineer chez Morgan Stanley :

28 févr. 2012
 A few questions on basic command-line syntax in Unix shells: 1. How would you log output and error messages from a command to a file? 2. How would you run the same command on every file in a directory? 3. How would you find the PID of a named process (say if you wanted to kill it)?5 réponses1. command >file 2>&1 2. cd dir; for i in *; do command; done 3. ps | grep processname or ps -C processname#3 I disagree, more like ps aux |awk '\$0 ~ /ProcessName/ && \$0 !~ /awk/ {print \$2}' If you want the PID#3 To find the PID: pgrep -xAfficher plus de réponses#3 - to find the PID Or simply use: pidofOpps!! there is typo; it should be: pidof

12 sept. 2012

### Cette question a été posée à un(e) Software Engineer chez McKesson :

6 juin 2011
 Given an array of 1001 elements, consists all numbers from 1-1000. Only one number is repeated. Write a function that returns the repeated number.4 réponsesHonestly, there's two possible answers you could give, depending on whether you want space efficiency or time efficiency (assuming that the array is *not* sorted). For time efficiency, ironically, the brute-force method is fastest. You make a counter array of size 1000, all indices initialized to 0, which takes O(n) time. Then, you run the following: for (int i = 0; i 1) // pre-increment the counter, then check if we've counted 2. return array[i]; } Overall, the time-efficient algorithm takes O(2n) = O(n) time, but takes O(n) additional space. The space-efficient algorithm just quick- or heap-sorts the array in place, then runs a binary search, comparing the value to the index. If the value == array[mid], search higher; otherwise search lower. Leave the loop once (high - low == 1), and then return that value. This will take O(n log n) time due to the sorting process, but only take up O(1) extra space. Of course, if the array comes pre-sorted, you would trivially just run binary search as described above.hey, i have one quick solution, create a function that will take up an initial value and end value, that will add up all numbers between them. create another function to add all elements in the array. call the first function, with value (1, 1000) and call the second function. compare the value. whatever the difference is, that is the repeated number.I think Lucas has the right idea with his counter but there's one flaw to his posted solution. His check should be (if ++counter[array[i]-1] > 1). If you do indeed declare the count tracker as int counter[1000] (which is the values counter[0] to counter[999]), doing counter[array[i]] would cause an out of bounds problem for array[i] = 1000. A third alternative, along the lines of dsutandi's idea, is to recognize (if you took a number series class) that the sum of 1 to n = n *(n+1) / 2. So you can loop through the incoming array, sum up all the values, then subtract that sum against the afforementioned value (inserting 1000 for n) and that would be your duplicate. For example: int sum = 0; for (int i = 0; i < 1001; i++){ sum += array[i]; } return sum - (1000*1001)/2;Afficher plus de réponseshere is my take : use following formula to get ideal sum : ideal_sum= n*(n+1)/2 real_sum=summation_of_all numbers in array repeated number = abs(real_sum-ideal_sum)

### Cette question a été posée à un(e) Senior Software Engineer chez Amazon :

16 août 2012
 Write a function that divides one number by another, without using the division operator, and make it better than O(n).7 réponsesThis can be done in a recursive function, the following code is in Python. # get result of a/b without using a "divide" operator def div(a,b): if a < b: return 0 else: return div(a-b, b)+1 This is how human being do the division naturally, however, the running time of this is O(n/m), where n is the size of a, and m is the size of b, which means, O(n/m) is guaranteed to be less than O(n), when m is larger than 1. -MaximThe answer above is still O(n). We can use binary search and find the answer in the interval [1,a] and use multiplication operator.Totally agree with Vasil. Other option: Long Division Algorithm. O(log n) anyway.Afficher plus de réponseswhy not just a * b^(-1) :-)// Write a function that divides one number by another, without using the division operator, // Assume that x%y = 0 // O(log n) (function() { 'use strict'; var divide = function(x, y) { var xLength = (x + '').length; var i = 0; var result = 0; var xAry = ('' + x).split(); var xStart = ''; for (i = 1; i = y) { xStart -= y; result = parseInt(result, 10) + 1; } } } return result; }; console.log(divide(1000, 4)); })();Use logarithms? O(1) log(x/y) = log(x) - log(y) = log(answer) answer = 10 ^ log(answer)Convert the number to divide into the base of the number that you are dividing with and then shift the 'bits' to the right by 1 then convert back to decimal

### Cette question a été posée à un(e) Software Developer chez Google :

29 janv. 2012
 Write a Java program that takes a 2D bitmap (represented as a 1D array of integers), and reverses it about its vertical axis.4 réponsesI asked the interviewer whether I'm also provided with a width, so that I know how to interpret the data in the 1D bitmap, and he said yes. From a high level, you need a doubly nested for loop: the outer one iterates over the rows, and the inner one iterates over the elements, reversing them as you go along.function flip(array) { if(array.length === 0) { return []; } var done = false; var pos = 0; var result = []; while(!done) { done = true; result[pos] = 0; for(var i = 0; i >> 1; if(array[i] > 0) done = false; } pos += 1; } return result; }In Python: array1d = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] #------------------------------------------------- def flipV(arr, width): rows = len(arr)//width for i in range(rows): # [0..rows) start = i * width # index of first element in row end = start + width - 1 # index of last element in row while start < end: arr[start],arr[end] = arr[end],arr[start] start += 1 end -= 1 #------------------------------------------------- def print2D(arr, width): rows = len(arr)//width for i in range(rows): # [0..rows) rowStart = i * width # start of row(i) for j in range(width): # [0..width) print(arr[rowStart + j], " ", end='') print() print(array1d) # original print2D(array1d, 4) flipV(array1d, 4) print(array1d) # flipped print2D(array1d, 4)Afficher plus de réponsesResult: >>> Input [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Output [3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12] 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12

### Cette question a été posée à un(e) Software Developer (New Grad) chez PDFTron :

13 oct. 2010
 How to multiply a number by 7 without using + and * operators?3 réponsesuse bit shifting.n=n<<3-ndo the left.bit shift operation by 3 and then subtract the result by original number . eg: n=1 ,then n=n<<3 -n gives 7 , if n=2 ,then gives 14

### Cette question a été posée à un(e) Associate Software Engineer chez Electronic Arts :

9 avr. 2009
 Given 100 white marbles and 100 black marbles and two jaws. Put these marbles in the two jars in a way that would maximize the chance of retrieving a white marble from any given jaw.4 réponsesdivide black marbles into the two jars first. then divide the white marbles on top of that in the two jars.Really that is what you would answer? What if they stirred the jars around after you distributed the marbles? Personally I think a better answer is to put 1 white marble in the first far and 99 white marbles and 100 black marbles in the second jar. If you choose the jar at random you now have a 74.87% chance of getting a white marble, regardless of the marbles position in the jar.qq is right, that is the optimum combination.Afficher plus de réponses2 colours, 2 jars. White in one, black in the other

### Cette question a été posée à un(e) Multimedia Driver Software Engineering chez Qualcomm :

27 juin 2012
 Explain a situation where a deadlock would occur.3 réponsesTwo processes each holding a resource tries to access the other's resource.Or you could forget to unlock.There are 4 conditions from Coffman's: A deadlock situation can arise if all of the following conditions hold simultaneously in a system:[1] 1. Mutual Exclusion: At least two resource must be non-shareable.[1] Only one process can use the resource at any given instant of time. 2. Hold and Wait or Resource Holding: A process is currently holding at least one resource and requesting additional resources which are being held by other processes. 3. No Preemption: The operating system must not de-allocate resources once they have been allocated; they must be released by the holding process voluntarily. 4. Circular Wait: A process must be waiting for a resource which is being held by another process, which in turn is waiting for the first process to release the resource. In general, there is a set of waiting processes, P = {P1, P2, ..., PN}, such that P1 is waiting for a resource held by P2, P2 is waiting for a resource held by P3 and so on until PN is waiting for a resource held by P1.[1][7]
110 de 5,951 Questions d'entretien d'embauche