Generate Character N-Grams from a URL
Updated
Problem statement
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 <= 1000001 <= n <= 100000urlcontains 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