FastPrepWord Search II

Word Search II

Kotak Mahindra Bank logoKotak Mahindra Bank● HardFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given a rectangular board of lowercase letters and a list of lowercase words, return every distinct input word that can be formed by a path through horizontally or vertically adjacent cells.

A cell may be used at most once within one word. Return matching words in the order of their first appearance in words.

Function

findWords(board: String[], words: String[]) → String[]

Examples

Example 1

board = ["oaan","etae","ihkr","iflv"]words = ["oath","pea","eat","rain"]return = ["oath","eat"]

Both returned words have valid adjacent-cell paths.

Example 2

board = ["ab","cd"]words = ["ab","abc","abd","ab"]return = ["ab","abd"]

Duplicate input words are returned once, and diagonal movement is not allowed.

Constraints

  • 1 <= board.length, board[i].length <= 12.
  • 1 <= words.length <= 30000.
  • 1 <= words[i].length <= 10.
  • Rows have equal length and all characters are lowercase English letters.

More Kotak Mahindra Bank problems

See Kotak Mahindra Bank hiring insights
public String[] findWords(String[] board, String[] words) {
    // Return found words in first-input order.
}
board["oaan","etae","ihkr","iflv"]
words["oath","pea","eat","rain"]
expected["oath", "eat"]
Checking account…