Questions d'entretien

Entretien pour Front End Engineer

-Menlo Park, CA

Meta

Given a grid of characters output a decoded message. The message for the following would be IROCKA. (diagonally down right and diagonally up right if you can't go further .. you continue doing this) I B C A L K A D R F C A E A G H O E L A D

Répondre

Réponses aux questions d'entretien

11 réponse(s)

9

as there are 21 characters and you describe a grid, I'm assuming it's 3x7: I B C A L K A D R F C A E A G H O E L A D Starting from the upper left and moving SE till a wall, then moving NE, then moving SE yields IROCLED, not IROCKA. However my human-powered fuzzy search is telling me it's much more likely that the answer is IROCKED, so I'm wondering whether the 1. author misremembered the original grid 2. the author misremembered the correct answer and the grid 3. I misunderstood the question.

confused le

2

var arr = [ ['I','B','C','A','L','K','A'], ['D','R','F','C','A','E','A'], ['G','H','O','E','L','A','D'] ]; var row = 0, col = 0; var totalCols = arr[0].length; var totalRows = arr.length; var msg = ''; while (col < totalCols) { msg += arr[row][col]; // row++ if less than total rows // row-- if back at row 0 row = (row === 0 || row < totalRows - 1) ? row + 1 : row - 1; // always go forward in column col++; } // returns 'IROCLED'

Utilisateur anonyme le

1

All solutions in here are wrong as they never go back up to the 0th row after first descent. ``` var arr = [ ['I','B','C','A','K','E','A'], ['D','R','F','C','A','E','A'], ['G','H','O','E','L','A','D'] ]; var row = 0, col = 0; var totalCols = arr[0].length; var totalRows = arr.length; var goingDown = false; var msg = ''; while (col < totalCols) { msg += arr[row][col]; // row++ if less than total rows // row-- if back at row 0 if (row === 0 || (row < totalRows - 1 && goingDown)) { row += 1; goingDown = true; } else { row -= 1; goingDown = false; } // always go forward in column col++; } console.log(msg) // IROCKED ```

Kyle le

0

var message = [ ['I', 'B', 'C', 'A', 'K', 'E', 'A'], ['D', 'R', 'F', 'C', 'A', 'E', 'A'], ['G', 'H', 'O', 'E', 'L', 'A', 'D'] ]; let forward = false, col = 0; for (let row = 0, len = message[0].length; row

Utilisateur anonyme le

0

var arr=[['I','B','C','A','L','K','A'],['D','R','F','C','A','E','A'],['G','H','O','E','L','A','D']] var result=""; var goDownward; for(var j=0,i=0;j

Pravin Mohite le

0

function decodeMessage(matrix) { let result = ''; let decode = function(matrix, i = 0, j = 0) { // check if matrix is null or empty if (matrix === null || matrix.length === 0) { return; } result += matrix[i][j]; //check the boundary of matrix with i and j let {x, y} = {x : matrix.length, y : matrix[0].length}; if ((i + 1) === x){ i -= 1; } else { i += 1; } j += 1; if (j === y) { return; } decode(matrix, i, j); } decode(matrix); return result; } let mat = [ ['I','B','C','A','L','K','A'], ['D','R','F','C','A','E','A'], ['G','H','O','E','L','A','D'] ]; console.log(decodeMessage(mat)); //IROCLED

Umesh Gohil le

0

function decode (matrix = []) { let i = 1 const sizeY = matrix.length - 1 const recurse = function (message, x, y) { if (y sizeY) { i = y = row.length) { return message } return recurse( message + row[x], x + 1, y + i, ) } return recurse('', 0, 0) } decode([ ['I', 'B', 'C', 'A', 'K', 'E', 'A'], ['D', 'R', 'F', 'C', 'A', 'E', 'A'], ['G', 'H', 'O', 'E', 'L', 'A', 'D'] ]) // IROCKED

Michael le

0

function getWord(met) { let arr = []; let i = met.length - 1; let j = met[0].length - 1; let a = 0; let direction = 1; for(let b = 0; b = i) { direction = -1; } else if(a === 0) { direction = 1; } a = a + direction; } return arr; } let sample= [ ['I', 'B', 'C', 'A', 'L', 'K', 'A'], ['D', 'R', 'F', 'C', 'A', 'E', 'A'], ['G', 'H', 'O', 'E', 'L', 'A', 'D'] ]; getWord(sample);

Susie.K le

0

const grid = [ ["I", "B", "C", "A", "L", "K", "A"], ["D", "R", "F", "C", "A", "E", "A"], ["G", "H", "O", "E", "L", "A", "D"] ]; const decoder = (grid)=>{ const rowsLen = grid.length; let isDown = true; const result = []; let column = 0; let row = 0; while(column < grid[0].length){ result.push(grid[row][column]); column++; if(isDown){ if(row+1 === rowsLen){ isDown = false; row--; }else{ row++; } }else{ if(row-1 <0){ isDown = true; row++; }else{ row--; } } } return result; } console.log(decoder(grid))

YoYo le

0

var arr=[['I','B','C','A','L','K','A'],['D','R','F','C','A','E','A'],['G','H','O','E','L','A','D']] var result=""; var goDownward; for(var j=0,i=0;j

Pravin Mohite le

0

var message = [ ['I', 'B', 'C', 'A', 'K', 'E', 'A'], ['D', 'R', 'F', 'C', 'A', 'E', 'A'], ['G', 'H', 'O', 'E', 'L', 'A', 'D'] ]; let forward = false, col = 0; for (let row = 0, len = message[0].length; row < len; row++) { console.log(message[col][row]); // I R O C K E D if (col === 0 || col === 2) forward = !forward; forward ? col++ : col--; }

Utilisateur anonyme le

Ajouter des réponses ou des commentaires

Pour commenter ceci, connectez-vous ou inscrivez-vous.