Unique Substrings in Wraparound String

We define the string base to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so base will look like this:

  • "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd...."

Given a string s, return the number of unique non-empty substrings of s that are present in base.

Example 1
Inputs = "a"
Output1
Only the substring "a" of s is in base.
Example 2
Inputs = "cac"
Output2
There are two substrings ("a", "c") of s in base.

Constraints

  • 1 <= s.length <= 10^5
  • s consists of lowercase English letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate