Q6.Find the pair of numbers with smallest difference #javascriptcoding #codinginterviews

preview_player
Показать описание
🌟 Ready for a challenge?
Practice it using the link in the bio! Go give it a go! 🚀

Question 6: Find the pair of numbers with smallest difference
Difficulty: Medium

Expected Optimal Space & Time Complexity:

O(nlog(n) + mlog(m)) time | O(1) space - where n is the length of the first input array and m is the length of the second input array

Write a function that takes in two non-empty arrays of integers, finds the pair of numbers (one from each array) whose absolute difference is closest to zero, and returns an array containing these two numbers, with the number
from the first array in the first position.

Note that the absolute difference of two integers is the distance between them on the real number line. For example, the absolute difference of -5 and 5 is 10, and the absolute difference of -5 and -4 is 1.

You can assume that there will only be one pair of numbers
with the smallest difference.

Sample Input:
arrayOne = [-1, 5, 10, 20, 28, 3]
arrayTwo = [26, 134, 135, 15, 17]

Sample Output:
[28, 26]

#interview
#interviewshorts #codinginterviewquestions #codinginterviews #quickinterviewprep #javascriptcoding #javascriptinterviewquestions #shorts
Рекомендации по теме
Комментарии
Автор

🌟 Ready for a challenge?
Practice it using the link in the bio! Go give it a go! 🚀

QuickInterviewPrep