Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    719 - Find K-th Smallest Pair Distance\.

    Hard

    The distance of a pair of integers a and b is defined as the absolute difference between a and b.

    Given an integer array nums and an integer k, return the <code>k<sup>th</sup></code> smallest distance among all the pairs nums[i] and nums[j] where 0 &lt;= i &lt; j &lt; nums.length.

    Example 1:

    Input: nums = 1,3,1, k = 1

    Output: 0

    Explanation: Here are all the pairs:

    (1,3) -> 2

    (1,1) -> 0

    (3,1) -> 2

    Then the 1<sup>st</sup> smallest distance pair is (1,1), and its distance is 0.

    Example 2:

    Input: nums = 1,1,1, k = 2

    Output: 0

    Example 3:

    Input: nums = 1,6,1, k = 3

    Output: 5

    Constraints:

    • n == nums.length

    • <code>2 <= n <= 10<sup>4</sup></code>

    • <code>0 <= numsi<= 10<sup>6</sup></code>

    • 1 &lt;= k &lt;= n * (n - 1) / 2

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer smallestDistancePair(IntArray nums, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait