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
- 1 <= s.length <= 105
- s consists of lowercase English letters.
Starter code (python)
class Solution(object):
def findSubstringInWraproundString(self, s):
"""
:type s: str
:rtype: int
"""
Related problems
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
- Roman to Integer (Easy)
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.