Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

471 Discussions

|

  • + 0 comments

    My Java 8 Solution

    public static String gridChallenge(List<String> grid) {
            for (int i = 0; i < grid.size(); i++) {
                char[] ca = grid.get(i).toCharArray();
                Arrays.sort(ca);
                grid.set(i, String.valueOf(ca));
            }
            
            for (int j = 0; j < grid.get(0).length(); j++) {
                for (int i = 1; i < grid.size(); i++) {
                    if (grid.get(i).charAt(j) < grid.get(i - 1).charAt(j)) return "NO";
                }
            }
            
            return "YES";
        }
    
  • + 0 comments

    No clever way of solving this; You have to iterate through the list, convert each string into a char array, sort them, create a new sorted gridand than iterate through the new grid with a nested for loop, and and check if the vertical lines are in order.

  • + 0 comments

    The answers for some of the hidden test cases are literally wrong according to the definition presented in the problem

  • + 0 comments

    static string gridChallenge(List grid) { for (int i = 0; i < grid.Count; i++) { char[] caracteres = grid[i].ToCharArray();

        for (int j = 0; j < caracteres.Length - 1; j++)
        {
            for (int k = 0; k < caracteres.Length - 1 - j; k++)
            {
                if (caracteres[k] > caracteres[k + 1])
                {
                    char temp = caracteres[k];
                    caracteres[k] = caracteres[k + 1];
                    caracteres[k + 1] = temp;
                }
            }
        }
    
        grid[i] = new string(caracteres);
    }
    
    for (int i = 0; i < grid.Count - 1; i++)
    {
        for (int j = 0; j < grid[i].Length; j++)
        {
            if (grid[i][j] > grid[i + 1][j])
            {
                return "NO";
            }
        }
    }
    
    return "YES";
    

    }

  • + 0 comments

    This question is garbage in its current state. The test cases do not conform to the requirements in the problem description, and the input parameters themselves contradict eachother.