Mbpp/597

❌ 均未通过 Base: FAIL Plus: FAIL
测试评估
指标结果
Base 测试FAIL
Plus 测试FAIL
代码长度1247 字符
模型生成的代码 (1247 字符)
def find_kth(arr1, arr2, k):
    """
    Find the k-th element (1-indexed) in the sorted union of two sorted arrays.
    
    Args:
        arr1: first sorted list
        arr2: second sorted list
        k: the 1-based index of the element to find
        
    Returns:
        The k-th smallest element in the union of arr1 and arr2
    """
    # Ensure arr1 is the smaller array to minimize binary search space
    if len(arr1) > len(arr2):
        arr1, arr2 = arr2, arr1

    n1, n2 = len(arr1), len(arr2)
    # If k is larger than total length, return None or handle as needed
    if k < 1 or k > n1 + n2:
        return None

    # Binary search on the smaller array
    low = max(0, k - n2)  # minimum elements we can take from arr1
    high = min(k, n1)     # maximum elements we can take from arr1

    while low <= high:
        i = (low + high) // 2      # number of elements taken from arr1
        j = k - i                  # number of elements taken from arr2

        # Elements just before the partitions (use -infinity if none)
        arr1_left_max = arr1[i - 1] if i > 0 else float('-inf')
        arr1_right_min = arr1[i] if i < n1 else float('inf')
        arr2_left_max = arr2[j - 1] if j > 0 else float('-inf')
        arr
Base 失败测试用例
  • [[2, 3, 6, 7, 9], [1, 4, 8, 10], 5]
Plus 失败测试用例
  • [[1, 2, 3], [], 1]