PIXELBANKv9.1.0
Menu

Word Search II

Given an m x n board of characters and a list of words, return all words found in the board. Each word must be constructed from letters of sequentially adjacent cells (horizontal or vertical), and the same cell may not be used more than once per word. Output found words sorted alphabetically.

Example:

Input:
oaan,etae,ihkr,iflv
oath,pea,eat,rain
Output:
eat oath
Reasoning:
  • The input is split into two parts: a 4x4 grid of characters (oaan, etae, ihkr, iflv) and a list of words (oath, pea, eat, rain).
  • We search for each word in the grid, checking for horizontal and vertical sequences of characters that match the word.
  • The words eat and oath are found in the grid: eat can be formed from the letters 'e', 'a', 't' in the grid, and oath can be formed from the letters 'o', 'a', 't', 'h' in the grid.
  • The found words are returned in alphabetical order, resulting in the output: eat oath

Constraints:

  • 1 <= m, n <= 12
  • board[i][j] is a lowercase English letter
  • 1 <= len(words) <= 3 * 10^4
solution.py

Test Results

0/0
Run code to see test results.
Word Search II - Hard | PixelBank