Server Finder with One Mismatch
Updated
Problem statement
A monitoring tool keeps a list of server names, servers. Operators type names into a search box, and the tool should still find the right server when one letter is wrong. You are given servers and a list of typed names, queries.
A query matches a server when both names have the same length and differ in at most one position. A name that is exactly the same also matches. Letters are never added or removed.
For each query, return the index of the server it matches. If several servers match, return the smallest index. If no server matches, return -1.
Return the answers in the order of queries.
Function
findServers(servers: String[], queries: String[]) → int[]Examples
Example 1
servers = ["delta","omega"]queries = ["delta","delte","omexa","dexte","omegas"]return = [0,0,1,-1,-1]Compare each query with each server name.
deltais the same as server 0, so the answer is 0.deltediffers fromdeltain one place (the last letter), so the answer is 0.omexadiffers fromomegain one place (the fourth letter), so the answer is 1.dextediffers fromdeltain two places (third and last letters) and is far fromomega, so the answer is -1.omegashas six letters and no server does, so the answer is -1.
Example 2
servers = ["cat","bat","rat"]queries = ["hat","cot","bat"]return = [0,0,0]hat is one letter away from all three servers, so the smallest index, 0, is the answer. cot is one letter away from cat only, so the answer is 0.
bat is the same as server 1, but it is also one letter away from cat at index 0. The smallest matching index wins, so the answer is 0, not 1.
Example 3
servers = ["x"]queries = ["y","xy","x"]return = [0,-1,0]A one-letter query is always within one letter of the one-letter server, so y and x give 0. xy has a different length, so it gives -1.
Example 4
servers = ["abcd","abdd","zzzz"]queries = ["abxd","zbzz","qqzz","abcd"]return = [0,2,-1,0]abxd is one letter away from abcd (index 0) and from abdd (index 1), so the answer is 0. zbzz is one letter away from zzzz only, so the answer is 2. qqzz is two letters away from zzzz, so the answer is -1. abcd matches index 0 exactly, and index 1 also matches, so the smallest, 0, is the answer.
Constraints
1 <= servers.length <= 10001 <= queries.length <= 10001 <= servers[i].length <= 201 <= queries[j].length <= 20- Every name contains only lowercase English letters.
- All names in
serversare different.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- Longest Substring Without Repeating CharactersOracle · ONSITE INTERVIEWOracle interview questions
- Route Pattern MatcherGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Longest Substring Without Repeating CharactersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Classify Password StrengthHackerRank · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
- Longest Substring Without Repeating CharactersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
- Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)