To the Top
File:  root - text - article - 2019 - 11 - word-search.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 781 Views, 13521 Search Bots | 136 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Amazon:

You are given a 2D array of characters, and a target string. Return whether or not the word target word exists in the matrix. Unlike a standard word search, the word must be either going left-to-right, or top-to-bottom in the matrix.

Example:


[['F', 'A', 'C', 'I'],
['O', 'B', 'Q', 'P'],
['A', 'N', 'O', 'B'],
['M', 'A', 'S', 'S']]


Given this matrix, and the target word FOAM, you should return true, as it can be found going up-to-down in the first column.

Here's the function signature:


def word_search(matrix, word):
# Fill this in.

matrix = [
['F', 'A', 'C', 'I'],
['O', 'B', 'Q', 'P'],
['A', 'N', 'O', 'B'],
['M', 'A', 'S', 'S']]
print word_search(matrix, 'FOAM')
# True
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Cateogry: Computing | 781 Views, 13521 Search Bots | 136 Words Subscribe to Feed Burner

Related Articles

  1. Algorithm Interview Question: Nth Fibonacci Number
  2. Algorithm Interview: Shifted String
  3. Daily Interview Problem: Jump to the End
  4. Daily Interview Problem: Find the k-th Largest Element in a List
  5. Daily Interview Question: Edit Distance
  6. Daily Interview Problem: Min Range Needed to Sort
  7. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  8. Two Tricks of Delphi
  9. Daily Interview Question: Longest Sequence with Two Unique Numbers
  10. Compare Version Numbers

Comments (0)

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">