As reported: Target online assessment (Sr Software Engineer, 2026; also the Cyber & Infra backend assessment, July 2026), question 1 of 3: edit distance with delete, replace and insert, for Q queries — from S given strings return the one with the minimum distance.
You are given S candidate strings and Q query strings. The edit distance between two strings is the fewest single-character operations that turn one into the other, where an operation is:
- insert a character,
- delete a character,
- replace a character with another.
For every query, return the candidate string with the smallest edit distance to it. If several candidates tie, return the one that appears first in candidates.
Example 1
candidates = ["kitten", "sitting", "mitten"]
queries = ["sittin", "bitten"]
Output: ["sitting", "kitten"]
"sittin" is 1 edit from "sitting" (insert g) and 2 from the others. "bitten" is 1 edit from both "kitten" and "mitten"; "kitten" comes first.
Example 2
candidates = ["abc", "", "xyz"]
queries = ["", "ab"]
Output: ["", "abc"]
Constraints: 1 ≤ S, Q ≤ 50; every string has 0 … 50 lowercase English letters; candidates may repeat.
Code runner format: two JSON lines: candidates, then queries. Implement closestStrings(candidates, queries) returning a list with one candidate per query, in query order.