We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defclosestNumbers(arr,n):# Write your code heresorted_arr=sorted(arr)smallest_diff=float('inf')diff_arr=[]foriinrange(n-1):first=sorted_arr[i]second=sorted_arr[i+1]diff=second-firstifdiff<smallest_diff:smallest_diff=diffdiff_arr=[first,second]elifdiff==smallest_diff:diff_arr.append(first)diff_arr.append(second)returndiff_arr
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Numbers
You are viewing a single comment's thread. Return to all comments →