क्रमबद्ध सरणी में तत्वों की निकटतम जोड़ी खोजने के लिए एक फ़ंक्शन लिखें।[1, 3, 4, 7, 8, 13]
def closest_pair(arr, num):
    i = 0
    j = len(arr) - 1
    diff = float('inf')
    res = []
    while(i < j):
        if(abs(arr[i] + arr[j] - num) < diff):
            diff = abs(arr[i] + arr[j] - num)
            res = [arr[i], arr[j]]
        if(arr[i] + arr[j] < num):
            i += 1
        else:
            j -= 1
    return res

arr = [1, 3, 4, 7, 8, 13]
num = 15

print(closest_pair(arr, num)) # [7, 8]