K22

Merge Two Binary Trees

Junior Level Candidate
Target Time: 15 - 20 Minutes
Type: ARRAY

Problem Statement & Objective

You are given two binary trees root1 and root2. Merge them into a single binary tree by summing overlapping node values.

Function Signature (Python)

merge_two_binary_trees(a1: list, a2: list) -> list

Input & Output Contract

Output Rule:Birleştirilmiş ağaç dizisi.

System Constraints

0 <= a1.length, a2.length <= 2000
-1000 <= degerler <= 1000

Example Execution Walkthrough

a1 = [1, 3, 2, 5], a2 = [2, 1, 3, None, 4, None, 7]
cevap: [3, 4, 5, 5, 4, None, 7]

Example Test Scenarios (3)

Example 1
Input:[[1,3,2,5],[2,1,3,null,4,null,7]]
Expected Output:[3,4,5,5,4,null,7]
Example 2
Input:[[1],[1,2]]
Expected Output:[2,2]
Example 3: Biri Boş
Input:[[],[1]]
Expected Output:[1]
Loading Python Editor...
Input Parameters
[
  [
    1,
    3,
    2,
    5
  ],
  [
    2,
    1,
    3,
    null,
    4,
    null,
    7
  ]
]
Expected Output
[
  3,
  4,
  5,
  5,
  4,
  null,
  7
]