상위 150개 인터뷰쉬움

최소 창 하위 문자열

'최소 창 하위 문자열' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

길이가 각각 mn인 두 개의 문자열 st이 주어지면 t의 모든 문자(중복 문자 포함)가 창에 포함되도록 s의 최소 창 하위 문자열을 반환합니다. 해당 하위 문자열이 없으면 빈 문자열 ""을 반환합니다.

답변은 고유한 것으로 보장됩니다.

minWindow(s: str, t: str) -> str 함수를 작성하세요.

제약
  • m == len(s), n == len(t)
  • 1 <= m, n <= 10^5
  • s and t consist of uppercase and lowercase English letters

Example 1
Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"
Explanation

The minimum window substring "BANC" (indices 9-12) contains 'A', 'B', and 'C' from t.

Example 2
Input
s = "a", t = "a"
Output
"a"
Explanation

The entire string s is the minimum window.

Example 3
Input
s = "a", t = "aa"
Output
""
Explanation

Both 'a's from t must be included. Since s only has one 'a', return empty string.

Need a Hint?
세트나 힙과 같은 슬라이딩 윈도우 관련 데이터 구조를 사용하는 것을 고려해보세요.
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 리소스

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