Count Sorted Vowel Strings | O(1) 1-Line Mathematical Solution w/ Explanation
Idea:\n\nThe mathematical solution is derived from Pascal\'s Triangle.\n\nThe formula for a triangular number is:\n\n       x * (x + 1)\n\t  -------------\n\t  
***Idea:***\n\nThe mathematical solution is derived from Pascal\'s Triangle.\n\nThe formula for a triangular number is:\n```\n       x * (x + 1)\n\t  -------------\n\t      1 * 2\n```\n...and the formula for a tetrahedral number is:\n```\n       x * (x + 1) * (x + 2)\n\t  -----------------------\n\t         1 * 2 * 3\n```\n...so the formula for the nth-simplex number is:\n```\n       x * (x + 1) * (x + 2) * ... * (x + n - 1)\n\t  -------------------------------------------\n\t                      n!\n```\nWe\'re dealing with a base of 5 vowels, so x = 5 and this formula starts to look like:\n```\n       5 * 6 * 7 * ... * (n + 4)\n\t  ---------------------------\n\t               n!\n```\n...but then we can realize that numbers start to cancel out from top to bottom, taking for example n = 10:\n```\n                       5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14\n\t  ------------------------------------------------------------\n\t   1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10\n```\nWe can factor out every number on the bottom greater than 4, and we\'ll also have the last four remaining numbers on the top, so the final formula ends up:\n```\n       (n + 1) * (n + 2) * (n + 3) * (n + 4)\n\t  ---------------------------------------\n\t               1 * 2 * 3 * 4\n```\n\n` `\n***Code:***\n\n```\nconst countVowelStrings = n => (n + 1) * (n + 2) * (n + 3) * (n + 4) / 24\n```
[]