Generate Character N-Grams from a URL
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.