• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 26, 2022 |6.3K Views
k-th smallest absolute difference of two elements in an array
  Share   Like
Description
Discussion

We are given an array of size n containing positive integers. The absolute difference between values at indices i and j is |a[i] – a[j]|. There are n*(n-1)/2 such pairs and we are asked to print the kth (1 <= k <= n*(n-1)/2) the smallest absolute difference among all these pairs. Examples: Input : a[] = {1, 2, 3, 4} k = 3 Output : 1 The possible absolute differences are : {1, 2, 3, 1, 2, 1}. The 3rd smallest value among these is 1. k-th smallest absolute difference of two elements in an array: https://www.geeksforgeeks.org/k-th-smallest-absolute-difference-two-elements-array/

Read More