FastPrepNearest Vocabulary Word
Problems/Nearest Vocabulary Word

Nearest Vocabulary Word

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Bing Applied Scientist internship report asks whether a word is in vocabulary V and, if absent, returns the most similar vocabulary word. Levenshtein distance, lexicographic ties, lowercase input, empty-vocabulary behavior, interface, and bounds are conventional enrichment.

Given a vocabulary array vocabulary and an input string word, return word when it appears in the vocabulary. Otherwise, return the vocabulary entry with the smallest Levenshtein edit distance from word.

One edit inserts, deletes, or replaces one character. Matching is case-sensitive. If several entries have the same minimum distance, return the lexicographically smallest one. Return the empty string when the vocabulary is empty.

Function

nearestVocabularyWord(vocabulary: String[], word: String) → String

Examples

Example 1

vocabulary = ["cat","bat","rat"]word = "hat"return = "bat"

All three vocabulary words are one replacement away; bat is lexicographically smallest.

Example 2

vocabulary = ["dog","cat"]word = "dog"return = "dog"

The input already belongs to the vocabulary, so it is returned unchanged.

Constraints

  • 0 <= vocabulary.length <= 1000
  • 0 <= vocabulary[i].length, word.length <= 100
  • All strings contain only lowercase English letters.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
  • Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Word BreakGoogle · ONSITE INTERVIEWGoogle interview questions
  • Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
  • Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Decode Numeric StringArcesium · ONSITE INTERVIEWArcesium interview questions
  • Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Count Vowel PermutationsZscaler · ONSITE INTERVIEWZscaler interview questions
  • Minimum Steps on a Circular Character DialNavan · ONSITE INTERVIEWNavan interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String nearestVocabularyWord(String[] vocabulary, String word) {
      // Write your code here.
    }

}
Checking account…