Algorithm · Apple · Medium
Problem An image collection stores every image as a d-component embedding vector. For a query vector q, determine which stored image is closest in similarity. Use cosine similarity as the comparison measure: \[ \text{sim}(a,b) = \frac{a\cdot b}{\ a\ \,\ b\ } \] Print the 0-based position of the image whose similarity score is greatest. When multiple images share the top score, choose the one with the lower index. Input Line 1 contains the integers n d. The following n lines…
Checking your access…