In order to solve this challenge: Challenge DescriptionBy starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27.   5  9 6 4 6 80 7 1 55 + 9 + 6 + 7 = 27Input sampleYour program should accept as its first argument a path to a filename. Input example is the following:59 64 6 80 7 1 5You make also check full input file which will be used for your code evaluation.Output sampleThe correct output is the maximum sum for the triangle. So for the given example the correct answer would be27I came up with the following code:static int GetMaxSum(int[][] numbers){    int firstCandidate = 0;    int secondCandidate = 0;    int max = 0;    for(int i = 1; i < numbers.Length; i++)    {        for(int j = 0; j < numbers[i].Length; j++)        {            firstCandidate = 0;            secondCandidate = 0;            if (j - 1 >= 0)            {                firstCandidate = numbers[i][j] + numbers[i - 1][j - 1];            }            if (j < numbers[i - 1].Length)            {                secondCandidate = numbers[i][j] + numbers[i - 1][j];            }            numbers[i][j] = firstCandidate > secondCandidate ? firstCandidate : secondCandidate;        }    }    int lastIndex = numbers.Length - 1;    var lastLine = numbers[lastIndex];    for(int i = 0; i < lastLine.Length; i++)    {        if(lastLine[i] > max)        {            max = lastLine[i];        }    }    return max;}static int[] ParseLine(string line){    string[] numbers = line.Trim().Split(' ');    int numbersLength = numbers.Length;    var result = new int[numbersLength];    for(int i = 0; i < numbersLength; i++)    {        result[i] = int.Parse(numbers[i]);    }    return result;}static void Main(string[] args){    var list = new List<int[]>();    int max = 0;    using (StreamReader reader = File.OpenText(args[0]))    {        while (!reader.EndOfStream)        {            string line = reader.ReadLine();            if (null == line)            {                continue;            }            list.Add(ParseLine(line));        }    }    max = GetMaxSum(list.ToArray());    Console.WriteLine(max);}and wanted some feedback on it. The basic idea is:Read all the fileTransform the content in a Lower Triangle Matrix structureCalculate max sums directly in the matrix (being that it's used only internally and it can be thrown once it's been processed)This was the most efficient - with regard to space and time - algorithm I could think of.Everything you can find - readability problems, efficiency problems, design problems, etc... - is fine.
Pass Triangle challenge
c#;programming challenge;dynamic programming
The GetMaxSum() function would be clearer if it were not so monolithic.  The general outline of the program is: update the numbers for each input row based on the previous intermediate results, and fetch the maximum at the end.  The program structure should reflect that.  Furthermore, you can avoid storing the entire triangle in memory by working as you encounter each row.The firstCandidate / secondCandidate comparison would be better written using Math.Max().Your ParseLine() can be simplified using Array.ConvertAll().  Since it's a one-liner, perhaps you don't need to write it as its own method at all.The epilogue can be simplified using LINQ.using System;using System.IO;using System.Linq;public class Triangle{    private int[] Row = new int[0];    public void AppendRow(string numbers)    {        int[] oldRow = Row;        // http://stackoverflow.com/a/1297250        Row = Array.ConvertAll(numbers.Trim().Split(' '), int.Parse);        for (int j = 0; j < Row.Length; j++)        {            Row[j] += Math.Max            (                (j > 0)             ? oldRow[j - 1] : 0,                (j < oldRow.Length) ? oldRow[j]     : 0            );        }    }    public int GetMaxSum()    {        return Row.Max();    }    public static void Main(string[] args)    {        Triangle triangle = new Triangle();        using (StreamReader reader = File.OpenText(args[0]))        {            while (!reader.EndOfStream)            {                triangle.AppendRow(reader.ReadLine());            }        }        Console.WriteLine(triangle.GetMaxSum());    }}