Your question is Top K Nearest Distances. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given an array of numeric distances distances, where each value represents the distance of one candidate vector from a query vector, return the indices of the k nearest neighbors in ascending order of distance. If two distances are equal, return the smaller index first. Write an optimized algorithm without using external libraries.
def top_k_nearest(distances, k):