Getting an array length in C# is a trivial task. All we need to so is call the Length property of the Array Class:

int[] arr = new int[17];
int arrLength = arr.Length;

 

Getting an array length in C++ might be less trivial:

int arr[17];
int arrSize = sizeof(arr) / sizeof(int);

Notice that sizeof(arr) returns the array size in bytes, not its length…


Continue Reading...

shootinfoot

There are several things a software developer can do to make his life much more difficult in the future. One day, some pieces of an old code may make us sorry we haven’t dedicated some more effort when we wrote it, so we have to pay attention and be careful. I am not talking about bad developers who always generate bad code because in those cases, every piece of their code is a disaster. Amit is talking about this issue in Terrible Code Examples – Methods From Hell. In this article I will point out some more .NET advanced issues that even the best developers have to be aware of. There are some things you can do which will cause some problems later on and you will be the one who have to handle with those issues. In other words, I will try to prevent you from shooting yourself in the foot.


Continue Reading...

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

Hey all! Its time for a new Challenge. But before that, last weeks answer. Well the answer could have been summed up by saying just traverse in reverse and return the second node . There were a few interesting answers among them Jonathan Gilbert’s who was the first to answer correctly: This seems pretty simple to […]


Continue Reading...

Recently, I ran into an interesting job interview question in C++ which I want to share. Lets take a look at the following code:

// Option A. 

char str1[] = "example";  

str1[1] = 'a';  

// Option B.  

char* str2 = "example";  

str2[1] = 'a';

What would happen if we compile and run this code ?


Continue Reading...

Yesterday I played around with WPF resources and stumbled on a very strange behavior. It seems that the order of the elements in the resources have some importance as to how the application handles them. A few code examples are attached


Continue Reading...

Lately I took part in several code reviews and I noticed that whenever people need to extract the month name from the datetime object many different solutions are presented. Some of the solutions were not very successful, so I decided to shed some light on this issue through an example. These are the most common […]


Continue Reading...