FastPrepFill and Sort Packed Missing-Number Grids

Fill and Sort Packed Missing-Number Grids

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

Problem statement

packed has four rows and 4k columns. Every consecutive four-column block is one 4 by 4 logical grid containing the strings 1 through 16, except that exactly one value is replaced by ?.

Fill every missing value, sort the logical grids by that numeric value ascending, and return the grids packed side by side in the new order.

Function

fillAndSortGrids(packed: String[][]) → String[][]

Examples

Example 1

packed = [["1","2","3","4","?","2","3","4"],["5","6","7","8","5","6","7","8"],["9","10","11","12","9","10","11","12"],["13","14","15","?","13","14","15","16"]]return = [["1","2","3","4","1","2","3","4"],["5","6","7","8","5","6","7","8"],["9","10","11","12","9","10","11","12"],["13","14","15","16","13","14","15","16"]]

The filled grids are reordered by missing value.

Example 2

packed = [["1","2","3","4"],["5","6","?","8"],["9","10","11","12"],["13","14","15","16"]]return = [["1","2","3","4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]

A single logical grid is filled without movement.

Constraints

  • 1 <= k <= 1000
  • packed.length == 4 and packed[r].length == 4k.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[][] fillAndSortGrids(String[][] packed) {
    // Write your code here.
}
packed[["1","2","3","4","?","2","3","4"],["5","6","7","8","5","6","7","8"],["9","10","11","12","9","10","11","12"],["13","14","15","?","13","14","15","16"]]
expected[["1", "2", "3", "4", "1", "2", "3", "4"], ["5", "6", "7", "8", "5", "6", "7", "8"], ["9", "10", "11", "12", "9", "10", "11", "12"], ["13", "14", "15", "16", "13", "14", "15", "16"]]
Checking account…