C# – Basic Exam – Biggest Triple

As I have mentioned here, I have participated in a competition for C# programmers. The second problem was concerning something quite standard – finding the biggest triple from a line of numbers.  With other words, one get as an input the following numbers:

2 3 4 3 3 3

The program runs and gives as input the three sequential numbers, which have the highest sum. In our case this is 2 3 4 because it is the leftmost sequence as well (part of the description of the problem).

So, I have started with the problem quite well – I managed to note that we do not have a number, telling us how many numbers should we have in a column, thus I have decided to record all of the values as string. After this I simply recorded the values of the string into an array, splited by the space and the rest was quite easy – assigning the highest sum comparing it with the sum of the next digits.

Thus, within about 40 minutes I was able to have 100 points from this problem. However, I liked the fact that there were tests with negative numbers and thus I have failed some of the tests initially:

Biggest Triple

 

Anyway, at this task my code looked more presentable and understandable. Here it is:

And the original solution from the author is present here:

Well so far so good 🙂

Tagged with: , , ,