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 | 785 Views, 13961 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 | 785 Views, 13961 Search Bots | 136 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Reverse Integer
  2. Daily Interview Problem: Word Ordering in a Different Alphabetical Order
  3. Daily Interview Puzzle: Intersection of Linked Lists
  4. Fix Brackets
  5. Find the non-duplicate number
  6. Daily Interview Problem: Maximum Profit From Stocks
  7. Reverse a Directed Graph
  8. [Daily Problem] Remove Consecutive Nodes that Sum to 0
  9. Algorithm Interview: Maximum Path Sum in Binary Tree
  10. Consecutive Ones

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />