Top 150-InterviewEinfach

Wortsuche II

Detaillierte Anleitung und Python-Implementierung für das Problem „Wortsuche II“.

Problemstellung

Einfach

Geben Sie bei einer m x n-Zeichentafel und einer Liste mit Zeichenfolgenwörtern alle Wörter auf der Tafel zurück.

Jedes Wort muss aus Buchstaben sequentiell benachbarter Zellen bestehen, wobei benachbarte Zellen horizontal oder vertikal benachbart sind. Die gleiche Buchstabenzelle darf in einem Wort nicht mehr als einmal verwendet werden.

Schreiben Sie eine Funktion findWords(board: List[List[str]], words: List[str]) -> List[str].

Einschränkungen
  • m == len(board)
  • n == len(board[i])
  • 1 <= m, n <= 12
  • board[i][j] is a lowercase English letter
  • 1 <= len(words) <= 3 * 10^4
  • 1 <= len(words[i]) <= 10
  • words consist of lowercase English letters
  • All the strings in words are unique

Beispiele

Example 1
Input
board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"]
Output
["oath","eat"]
Explanation

The words "oath" and "eat" can be found on the board. "pea" and "rain" cannot.

Example 2
Input
board = [["a","b"],["c","d"]], words = ["abcb"]
Output
[]
Explanation

The word "abcb" requires using the 'b' cell twice, which is invalid.

Need a Hint?
Erwägen Sie die Verwendung von Trie-spezifischen Datenstrukturen wie Sets oder Heaps.
Edge Cases to Watch
  • Leere Eingabestrukturen
  • Einzelelementeingaben
  • Große numerische Grenzen

Bereit zur Lösung?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Im Editor öffnen
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Empfohlene Python-Ressourcen

Erweitern Sie Ihr Wissen mit zugehörigen interaktiven Tutorials, Spickzetteln und Codevergleichen.