Grid Challenge Discussions | | HackerRank

Grid Challenge

Sort by

recency

|

482 Discussions

|

  • + 0 comments

    One of the test cases are wrong, the N value isn't the number of elements on the list and the lenght of each string?

    3

    3

    abc

    lmp

    qrt

    3

    mpxz

    abcd

    wlmf

    4

    abc

    hjk

    mpq

    rtv

  • + 0 comments

    Yeah kinda annoying for them to say square grid which implies elements in input have the same length as the number of inputs.

  • + 0 comments

    Problem and tests are not consistent, the problem states square grids but the test have non square grids.

  • + 0 comments

    Scala Solution

    def gridChallenge(grid: Array[String]): String = {
        // Write your code here
        val sortedGrid = grid.map(row => row.sorted)
        val n = sortedGrid.length
        val m = sortedGrid(0).length
        for (col <- 0 until m) {
        for (row <- 0 until n - 1) {
          if (sortedGrid(row)(col) > sortedGrid(row + 1)(col)) {
            return "NO"
          }
        }
      }
    
      "YES"
    
    
        }
    
  • + 0 comments

    I had to assume column length can differ from number of strings/rows/n;

    int cols = grid[0].Length;