6 kyu

Smallest Difference

Description:

Given two arrays of integers, find the pair of values with the smallest difference and return that difference.

If both arrays are empty, return -1.

If one array is empty, return the smallest value from the non-empty array.

Note: Try to solve this without brute force.

Example:

  arr1 = [1, 3, 5, 23, 5]
  arr2 = [45, 34, 67, 2, 0]
  
  Output = 1
  
Example empty array:

  arr1 = [1, 3, 5, 23, 5]
  arr2 = []
  
  Output = 1
  
Example two empty arrays:

  arr1 = []
  arr2 = []
  
  Output = -1
Arrays
Algorithms
Fundamentals

Stats:

CreatedDec 24, 2016
PublishedDec 24, 2016
Warriors Trained535
Total Skips8
Total Code Submissions989
Total Times Completed222
JavaScript Completions222
Total Stars20
% of votes with a positive feedback rating87% of 95
Total "Very Satisfied" Votes77
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes6
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • PostPunk Avatar
  • ZED.CWT Avatar
Ad