FastPrepRank Vectors by Dot-Product Similarity
Problems/Rank Vectors by Dot-Product Similarity

Rank Vectors by Dot-Product Similarity

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source asks for ranking other vectors by similarity to one query vector. It does not specify a metric, normalization, ties or numerical representation. This practice chooses integer dot-product similarity, all candidate indices, decreasing scores and increasing-index ties, with bounded same-dimension inputs. About80% of the reported ranking task is represented; cosine similarity and Euclidean distance are different possible metric choices and are not claimed as source requirements.

For this exercise, measure similarity with the dot product. Given an integer query vector query and candidate vectors vectors of the same dimension, the score of candidate i is the sum of query[j] * vectors[i][j] over every coordinate.

Return every candidate’s zero-based index in decreasing score order. Break equal scores by increasing index. Do not normalize vectors or return the score values. An empty candidate list returns an empty result.

Function

rankVectors(query: int[], vectors: int[][]) → int[]

Examples

Example 1

query = [2,-1]vectors = [[1,0],[0,3],[2,2],[-1,-2]]return = [0,2,3,1]

The scores in input order are 2, -3, 2 and 0. Indices 0 and 2 tie, so index 0 comes first. The result is [0,2,3,1].

Example 2

query = [0,0]vectors = [[9,-4],[0,0],[-2,8]]return = [0,1,2]

A zero query gives every candidate score 0. The tie rule therefore returns the original index order [0,1,2].

Constraints

  • 1 <= query.length <= 200
  • 0 <= vectors.length <= 2000
  • 1 <= vectors[i].length <= 200
  • Every candidate has the same length as query.
  • -1000 <= query[j] <= 1000
  • -1000 <= vectors[i][j] <= 1000

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public int[] rankVectors(int[] query, int[][] vectors) {
        // Write your code here
    }
}
Checking account…