The twelfth post of the series of programming job interview challenge is out, 28 readers provided answers to job interview challenge #11. I have to admit that I probably failed explaining what I was looking for in challenge #11, because I asked you to provide the best algorithm in both manners: performance and memory. What I really meant is that performance is most important but don’t neglect the memory issue. Due to my little “embarrassing failure”, there are two groups of correct answers - the performance oriented and the memory oriented.
The correct answer which I was looking for (best at performance) as Alex, the first one to provide a detailed solution (its two times in a row), wrote:
Continue Reading...
The eleventh post of the series of programming job interview challenge is out. 75 readers provided answers to job interview challenge #10 and most of them had the correct solution. The correct answer as Alex, the first one to provide a detailed solution, wrote:
Here’s an O(N) solution:
Have one variable that stores the sum of all the values. Iterate through the list to add all numbers to the variable, which for simplicity I will call “listSum”.
Now, take the theoretical sum of all numbers between 1…n+1: This can be computed in O(1), as the sum of numbers up to N is n(n+1)/2: So for numbers up to n+1, it’d be (n+1)(n+2)/2 (for instance, if the array is of size 9, we’d do 10*(11)/2, or a theoretical sum of 55). Call this sum “allSum”.
The missing number will be the result of computing “allSum - listSum”.
O(N)complexity, with only two tracking variables.
Continue Reading...
LINQ to SQL maps the relational database into an object model, and when the program runs the queries in the object model are translated into SQL. SQL contains Aggregate functions like SUM, AVG, MIN, MAX and more. Lets see how this functionality can be implemented using LINQ Enumerable standard aggregation operators. You can also create [...]
Continue Reading...