Example CodeSignal questions for software engineering interviews

You might be given a matrix of integers area of measurement top × width representing a sport area, and in addition a matrix of integers determine of measurement 3 × 3 representing a determine. Each matrices comprise solely 0s and 1s, the place 1 implies that the cell is occupied, and 0 implies that the cell is free.

You select a place on the high of the sport area the place you set the determine after which drop it down. The determine falls down till it both reaches the bottom (backside of the sector) or lands on an occupied cell, which blocks it from falling additional. After the determine has stopped falling, among the rows within the area could turn out to be totally occupied.

demonstration

Your process is to search out the dropping place such that a minimum of one full row is shaped. As a dropping place, you must return the column index of the cell within the sport area which matches the highest left nook of the determine’s 3 × 3 matrix. If there are a number of dropping positions satisfying the situation, be at liberty to return any of them. If there aren’t any such dropping positions, return -1.

Observe: The determine have to be dropped in order that its whole 3 × 3 matrix matches inside the sector, even when a part of the matrix is empty. 

Instance

For
area =  [[0, 0, 0],
          [0, 0, 0],
        [0, 0, 0],
         [1, 0, 0],
        [1, 1, 0]]

and
determine = [[0, 0, 1],
         [0, 1, 1],
         [0, 0, 1]]

the output needs to be answer(area, determine) = 0.

As a result of the sector is a 3 x 3 matrix, the determine may be dropped solely from place 0. When the determine stops falling, two totally occupied rows are shaped, so dropping place 2 satisfies the situation.

example 1

For
area =  [[0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0],
          [1, 1, 0, 1, 0],
          [1, 0, 1, 0, 1]]

and
determine = [[1, 1, 1],
          [1, 0, 1],
          [1, 0, 1]]

the output needs to be solution(area, determine) = 2.

The determine may be dropped from three positions: 0, 1, and 2. As you’ll be able to see beneath, a totally occupied row might be shaped solely when dropping from place 2:

example 2

For
area =  [[0, 0, 0, 0],
          [0, 0, 0, 0],
          [0, 0, 0, 0],
          [1, 0, 0, 1],
          [1, 1, 0, 1]]

and
determine = [[1, 1, 0],
          [1, 0, 0],
          [1, 0, 0]]

the output needs to be answer(area, determine) = -1.

The determine may be dropped from two positions, 0 and 1, and in each instances, a totally occupied line gained’t be obtained:

example 3

Observe that the determine may technically kind a full row if it was dropped one place additional to the correct, however that isn’t a sound dropping place, as a result of the three x 3 determine matrix wouldn’t be totally contained with the sector.

More Posts