상위 150개 인터뷰중간

문자열 인터리브

'인터리빙 문자열' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

중간

문자열 s1, s2, s3이 주어지면 s3이 s1과 s2의 인터리빙으로 형성되는지 확인합니다.

두 문자열 s와 t의 인터리빙은 s = s1 + s2 + ... + sn, t = t1 + t2 + ... + tm, |n - m|과 같이 비어 있지 않은 하위 문자열로 분할되는 구성입니다. <= 1이고 인터리브된 문자열은 s1 + t1 + s2 + t2 + ... 또는 t1 + s1 + t2 + s2 + ...입니다.

isInterleave(s1: str, s2: str, s3: str) -> bool 함수를 작성하세요.

제약
  • 0 <= len(s1), len(s2) <= 100
  • 0 <= len(s3) <= 200
  • s1, s2, and s3 consist of lowercase English letters

Example 1
Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
Output
True
Explanation

aadbbcbcac can be formed by interleaving "aabcc" and "dbbca".

Example 2
Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
Output
False
Explanation

It is impossible to interleave s1 and s2 to obtain s3.

Need a Hint?
세트나 힙과 같은 2D DP 관련 데이터 구조를 사용해 보세요.
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 리소스

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