FastPrepGenerate Character N-Grams from a URL
Problems/Generate Character N-Grams from a URL

Generate Character N-Grams from a URL

Microsoft logoMicrosoft● EasyNEW GRADPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Research Security and AI internship interview asks the candidate to generate n-grams from a URL and then discusses encoding and sparse features. Character-level windows, raw URL handling, duplicate retention, interface, and bounds are conventional enrichment.

Given a URL string url and a positive integer n, return every overlapping character n-gram in left-to-right order.

Use the URL exactly as supplied: matching is case-sensitive, no decoding or normalization is performed, and repeated n-grams are retained. If n is greater than the URL length, return an empty array.

Function

urlNGrams(url: String, n: int) → String[]

Examples

Example 1

url = "abc"n = 2return = ["ab","bc"]

The two overlapping length-two windows begin at indexes 0 and 1.

Example 2

url = "aaaa"n = 2return = ["aa","aa","aa"]

Each overlapping occurrence is retained, even when the n-gram text repeats.

Constraints

  • 0 <= url.length <= 100000
  • 1 <= n <= 100000
  • url contains printable ASCII characters.

More Microsoft Phone Screen questions

  • Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
  • Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
  • Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
  • Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
  • 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
  • Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
  • Most Visited String SectorsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Find First Anagram IndexDatabricks · PHONE SCREENDatabricks interview questions
  • Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
  • Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
  • Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
  • Minimum Window SubstringLyft · PHONE SCREENLyft interview questions
  • Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions
  • Find Word-Multiset WindowsAmazon · PHONE SCREEN
  • Find the First Contiguous HaikuFaire · PHONE SCREEN
  • Shortest Deletion for a Distinct RemainderGoogle · PHONE SCREENGoogle interview questions
  • Longest Substring Without Repeating CharactersCapgemini · PHONE SCREENCapgemini 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[] urlNGrams(String url, int n) {
      // Write your code here.
    }

}
Checking account…