23. Count Sorted Vowel Strings
Given an integer n
, return the number of strings of length n
that consist only of vowels (a
, e
, i
, o
, u
) and are lexicographically sorted.
A string s
is lexicographically sorted if for all valid i
, s[i]
is the same as or comes before s[i+1]
in the alphabet.
Example 1:
Example 2:
Example 3:
Solution: (Using Backtracking to generate all possible strings and counting length)
Solution: (DP)
Approach: Count the no of ways from 'u' in each case and check the pattern.
Last updated