626. Embarking on the Path of Knighthood
You have been chosen as the squire of a skilled knight who wields two swords simultaneously. In order to become a knight yourself, you must assist him in selecting a pair of swords based on their difference in length. You will be given the lengths of each sword, and your task is to find the Kth smallest difference between any two swords. Complete this task promptly to begin your journey towards knighthood.
The first line contains two integers K and N (the size of the array). The second line contains N space-separated integers.
Print the Kth smallest difference.
3 1 1 3 1
- n == nums.length - 2 <= n <= 1e4 - 0 <= nums[i] <= 1e6 - 1 <= k <= n * (n - 1) / 2