DSA 섹션중간

AVL 트리

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

문제 설명

중간

이진 트리 tree_arr의 배열 표현을 취하고 트리가 높이 균형을 이루고(모든 노드에 대해 왼쪽 및 오른쪽 하위 트리의 높이가 최대 1만큼 다름) 유효한 BST인 경우 True를 반환하고, 그렇지 않으면 False을 반환하는 is_avl_balanced(tree_arr) 함수를 작성하세요.

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

Example 1
Input
tree_arr = [3, 9, 20, None, None, 15, 7]
Output
True
Explanation

The tree is a valid BST and the depth difference of left/right subtrees of all nodes is at most 1.

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

The tree is unbalanced because leaf node 4 is at depth 4 while right subtree of node 1 is empty.

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

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