Skip to content

Instantly share code, notes, and snippets.


McLarenCollege/ Secret

Last active Jun 2, 2021
What would you like to do?

Find Word

Time Allowed: 40 minutes

Write a function findWord which takes a matrix of characters and a target word, and returns true if the word appears vertically at some position in the matrix


  • Every element in the matrix will be a string of length 1
  • You should only consider the top-down direction (ie. not left-right or down-up, etc)

Example 1

let easyPuzzle = [
    ['b', 'a', 't'],
    ['i', 'i', 'p'],
    ['t', 'o', 'n']
console.log(findWord(easyPuzzle, 'bit')); // should print true
console.log(findWord(easyPuzzle, 'bat')); // should print false

Example 2

let hardPuzzle = [
    ['y', 'o', 't', 'v'],
    ['k', 'c', 'p', 's'],
    ['t', 'h', 'n', 's'],
    ['t', 'a', 'o', 'e'],
    ['t', 't', 'a', 'i'],
console.log(findWord(hardPuzzle, 'chat')); // should print true
console.log(findWord(hardPuzzle, 'set')); // should print false
console.log(findWord(hardPuzzle, 'i')); // should print true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment