Test H1

Test H2

Step 1: Partition the Arrays

Partition the smaller array (let's say A) at a midpoint i. Based on the total number of elements, a corresponding partition point j is determined in the other array (B).

The goal is to find partitions where:

# Initialize pointers for binary search
l, r = 0, len(A) - 1

while True:
    i = (l + r) // 2
    j = half - i - 2

Step 2: Check Partitions and Adjust

Compare the elements at the boundaries of the partitions (Aleft, Aright, Bleft, Bright). If the partitions are incorrect, adjust the binary search range.

    if Aleft <= Bright and Bleft <= Aright:
        # Correct partition found
        break
    elif Aleft > Bright:
        r = i - 1
    else:
        l = i + 1

Step 3: Calculate the Median

Once the correct partitions are found, calculate the median.

# For odd number of elements
if total % 2:
    return min(Aright, Bright)

# For even number of elements
return (max(Aleft, Bleft) + min(Aright, Bright)) / 2