Find K-th Smallest Pair Distance
Signals to notice
Brute force first
Compute all n(n-1)/2 distances, sort, return kth. Generates all pairs even though we only need one. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
The key insight
Sort the array. Binary search on the distance value: for each candidate distance d, count how many pairs have distance ≤ d using two pointers. Find the smallest d with count ≥ k. The goal is not to be clever for its own sake, but to remember the one relationship that keeps the solution grounded as you move forward.
What must stay true
In a sorted array, counting pairs with distance ≤ d is using two pointers (for each right pointer, find the leftmost left pointer where right - left ≤ d). The count is monotonically non-decreasing in d. If that remains true after every update, the rest of the reasoning has a stable place to stand.
Easy way to go wrong
The binary search is on the distance value (0 to max-min), NOT on array indices. Each candidate distance is validated by counting pairs ≤ that distance. The fix is usually to return to the meaning of each move, not just the steps themselves.