Rank Unseen Items by Embedding Similarity
Updated
Problem statement
You are given one user embedding and n item embeddings of the same dimension. The similarity of an item is the dot product of its embedding with the user embedding.
Exclude every item index in seenItemIndexes. Return all remaining item indices ordered from highest similarity to lowest. Break an exact score tie by the smaller item index.
Function
rankUnseenItems(userEmbedding: double[], itemEmbeddings: double[][], seenItemIndexes: int[]) → int[]Examples
Example 1
userEmbedding = [1.0,2.0]itemEmbeddings = [[1.0,0.0],[0.0,2.0],[2.0,1.0],[-1.0,0.0]]seenItemIndexes = [1]return = [2,0,3]After excluding item 1, the dot products are 4, 1, and -1 for indices 2, 0, and 3.
Example 2
userEmbedding = [1.0,1.0]itemEmbeddings = [[2.0,0.0],[0.0,2.0],[1.0,1.0]]seenItemIndexes = []return = [0,1,2]All three scores are 2, so indices determine the order.
Constraints
1 <= itemEmbeddings.length <= 100000.1 <= userEmbedding.length <= 200, and every item embedding has that length.- All coordinates are finite doubles with absolute value at most
10^6. - Seen indices are distinct and valid.
More Yahoo interview questions
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Assign CookiesAmazon · PHONE SCREEN
- Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
- Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Parse and Sort Integer DataLegora · PHONE SCREEN