Grid Challenge Discussions | | HackerRank

Grid Challenge

  • + 1 comment

    C#

        public static string gridChallenge(List<string> grid)
        {
            const string YES = "YES";
            const string NO = "NO";
            var rowSize = grid.Count - 1;
            var columnSize = grid.First().Length;
            var horizontallyOrderedNumericRows = grid.Select(st => st.Select(ch => (int)ch).Order().ToArray()).ToArray();
            
            for (int i = 0; i < columnSize; i++)
            {
               for (int j = 0; j < rowSize; j++)
               {
                    if (horizontallyOrderedNumericRows[j][i] > horizontallyOrderedNumericRows[j + 1][i])
                    {
                        return NO;
                    }
               } 
            }
            
            return YES;
        }