상위 150개 인터뷰쉬움

단어 검색 II

'단어 검색 II' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

m x n 개의 문자 보드와 문자열 단어 목록이 주어지면 보드의 모든 단어를 반환합니다.

각 단어는 순차적으로 인접한 셀의 문자로 구성되어야 하며, 인접한 셀은 수평 또는 수직으로 이웃합니다. 동일한 문자 셀은 한 단어에서 두 번 이상 사용될 수 없습니다.

findWords(board: List[List[str]], words: List[str]) -> List[str] 함수를 작성하세요.

제약
  • 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

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?
세트나 힙과 같은 Trie 특정 데이터 구조를 사용하는 것을 고려해보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

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

편집기에서 열기
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

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.