Grid Challenge Discussions | | HackerRank

Grid Challenge

  • + 0 comments

    C#

    public static string gridChallenge(List<string> grid)
        {
            for (int i = 0; i < grid.Count(); i++)
            {
                char[] characters = grid[i].ToArray();
                Array.Sort(characters);
                grid[i] = new string(characters);
            }
    
            bool alphaOrder = true;
            if (grid.Count > 1)
            {
                for (int i = 0; i < grid.Count() - 1; i++)
                {
                    for (int j = 0; j < grid[0].Count(); j++)
                    {
                        if (String.Compare(grid[i].Substring(j, 1), grid[i + 1].Substring(j, 1)) > 0)
                        {
    
                            alphaOrder = false;
                        }
                    }
                }
            }
    
            return alphaOrder ? "YES" : "NO";
    
        }