Zepruv › Coding problems

Unique Substrings in Wraparound String

Medium · String, Dynamic Programming

We define the string base to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so base will look like this:
Given a string s, return the number of unique non-empty substrings of s are present in base.

Example 1

Input: s = "a"
Output: 1

Only the substring "a" of s is in base.

Example 2

Input: s = "cac"
Output: 2

There are two substrings ("a", "c") of s in base.

Example 3

Input: s = "zab"
Output: 6

There are six substrings ("z", "a", "b", "za", "ab", and "zab") of s in base.

Constraints

Starter code (python)

class Solution(object):
    def findSubstringInWraproundString(self, s):
        """
        :type s: str
        :rtype: int
        """
        

Related problems

Previous: Minimum Moves to Equal Array Elements II · Next: Validate IP Address · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.