Algorithm · ByteDance · Easy
Meaning Similarity (Embeddings + Cosine Similarity) You receive two pieces of text, text1 and text2, along with an encoder encode(text) -> vector (such as a sentence-embedding model). Build a function that measures how semantically alike the texts are by taking the cosine similarity of their embedding vectors: \[ \text{sim}(a,b) = \frac{a \cdot b}{ a 2 b 2} \] Input First line: the string text1 Second line: the string text2 Output Output a single floating-point value…
Checking your access…