DP Solution with  Explanation
It is an awesome problem. Lets deep dive in it.\n\nSo, they are asking the number of ways in which we can generate  lexographically sorted strings of length n, 
It is an awesome problem. Lets deep dive in it.\n\nSo, they are asking the number of ways in which we can generate  lexographically sorted strings of length n, which only contains vowels.\n\nNow lets think about it.\nSuppose if  `n=1` then the possible strings would be ```"a","e","i","o","u"```.\n\n\nNow lets make an approach.\n\nLets create a 2-D array of size 5 * n and for our example lets take ```n=3```\nSo here is our array.\n\n![image](https://assets.leetcode.com/users/images/5cfacf83-2f89-4369-9fd6-c9d1b01d3f6a_1652281456.4877005.jpeg)\n\nHere we will store the number of strings we that will end on respective vowel for the given n.\nNow for n=1, all the values will be 1.\n\nLets fill it for n=2.\nFor string to be ending on ```a``` we have only one way i.e all the characters will be ```\'a\'```.\n\nFor string  to be ending on ```b``` we have two options that either append ```\'b\'``` on string which previously ended on ```a``` or append ```\'b\'``` to the string which previously ended on ```b```.\n\nFor string to be ending on ```c``` we have three options that we append ```\'c\'``` on string ending with ```a``` or ```b``` or append ```\'c\'``` to the string which previously ended on ```c```.\n\nIt hope you got the idea :)\n\nNow lets fill our array.\n\n![image](https://assets.leetcode.com/users/images/c5cf43d8-ae70-47b7-afba-eb7e3f9c7394_1652282112.450616.jpeg)\n\nAt last the sum of last column will be our answer.\n\nAwesome we solved it !!!\n\nBut can we do better? Can we do it in O(1) space?\n\nIf you look closely we are only using the previous values of the column. So there is no need to use this array we will replace it by 5 variables which will be storing the content of column values.\n\nHere is my code :\n\n```\nclass Solution {\n    public int countVowelStrings(int n) {\n        int a=1,e=1,i=1,o=1,u=1;\n        for(int index=1;index<n;index++){\n            int aNew=a,eNew=a+e,iNew=a+e+i,oNew=a+e+i+o,uNew=a+e+i+o+u;\n            a=aNew;\n            e=eNew;\n            i=iNew;\n            o=oNew;\n            u=uNew;\n        }\n        return a+e+i+o+u;\n    }\n}\n```\n\nHope u understood the solution.\n\n \n
['Java']