Solución

@aamardach_0b51404f·29/5/2026TypeScript
solution.tsTypeScript
function wordInMatrix(matrix: string[][], word: string): boolean {
  // TODO: Implementa tu solución aquí
  var result: boolean = false;

  //Iteraciones para X
  var wordx: string = '';
  for(let i = 0; i < matrix.length; i ++){
    wordx = '';
    for(let j = 0; j < matrix[i].length; j ++){
      //supongamos que es la 3ra iteración, entra a ["A","N","O","B"] y el valor de word es "ANOB"
      wordx = wordx + matrix[i][j];
    }
    if(wordx === word) {
      result = true;
      break;
    }
  }

  //Iteraciones para Y
  /*supongamos que el valor de word es "ABNA"
    ["F","A","C","I"],
    ["O","B","Q","P"],
    ["A","N","O","B"],
    ["M","A","S","S"]
  */
  var wordy: string = '';
  var refBef: number = 0;
  for(let i = 0; i < matrix.length; i ++){

    wordy = wordy + matrix[i][refBef];

    if(wordy === word) {
      result = true;
      break;
    }
    if(i === matrix.length) {
      wordy = '';
      refBef ++;
    }
  }

  return result;
}

// No modificar: necesario para evaluar el resultado.
export { wordInMatrix };

/* wordInMatrix([
  ["F","A","C","I"],
  ["O","B","Q","P"],
  ["A","N","O","B"],
  ["M","A","S","S"]
  ], "FOAM")→false(esperado: true)*/

/* wordInMatrix([
  ["A","B"],
  ["C","D"]
  ], "AC")→false(esperado: true) */

// wordInMatrix([["F","A","C","I"],["O","B","Q","P"],["A","N","O","B"],["M","A","S","S"]], "MASS")→false(esperado: true)

// wordInMatrix([["F","A","C","I"],["O","B","Q","P"],["A","N","O","B"],["M","A","S","S"]], "FOAB")→false

// wordInMatrix([["F","A","C","I"],["O","B","Q","P"],["A","N","O","B"],["M","A","S","S"]], "BOPS")→false

// wordInMatrix([["H","E","L","L","O"]], "HELLO")→false(esperado: true)
0respuestas
Respuestas

Aún no hay respuestas

¡Sé el primero en responder!

Escribir un comentario

Recuerda ser amable. Estás comentando la solución de otra persona. Comparte tu perspectiva de forma constructiva y respetuosa.

Debes iniciar sesión para publicar un comentario.