DSA 섹션쉬움

BST

'BST' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

이진 트리 tree_arr(인덱스 0의 루트, 2i+12i+2i의 자식, None은 빈 노드를 나타냄)의 배열 표현을 취하고 유효한 이진 검색 트리(BST)인 경우 True을 반환하고 그렇지 않은 경우 False을 반환하는 함수 is_valid_bst(tree_arr)을 작성하세요.

제약
  • 0 <= len(tree_arr) <= 1000

Example 1
Input
tree_arr = [2, 1, 3]
Output
True
Explanation

The left child 1 is smaller than root 2, and right child 3 is greater than root 2.

Example 2
Input
tree_arr = [5, 1, 4, None, None, 3, 6]
Output
False
Explanation

The root value is 5, but its right child 4 contains a left child 3 which is smaller than 5.

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 리소스

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