❇ longest-substring-of-all-vowels-in-order👌 🏆O(N)❤️ Javascript🎯 Memory👀95.45%🕕 ++Explanation✍️
\n\nTime Complexity: O(N)\nSpace Complexity: O(1)\n\n\nvar longestBeautifulSubstring = function (word) {\n    const pattern = [\'a\', \'e\', \'i\', \'o\', \'u\'
![image](https://assets.leetcode.com/users/images/b9ecc654-8dbb-4ae1-b036-808c1a960f31_1716053604.2757008.png)\n\nTime Complexity: O(N)\nSpace Complexity: O(1)\n\n```\nvar longestBeautifulSubstring = function (word) {\n    const pattern = [\'a\', \'e\', \'i\', \'o\', \'u\'];\n    let patternIndex = 0;\n    let output = 0;\n    let startPatternIndex = null;\n    let index = 0;\n    for (index = 0; index < word.length; index++) {\n        const element = word[index];\n        if (patternIndex === 4 && element === pattern[patternIndex]) {\n            if (element === pattern[pattern.length - 1]) {\n                const size = index - startPatternIndex + 1;\n                output = Math.max(output, size);\n            }\n        } else if (element === pattern[patternIndex]) {\n            if (startPatternIndex === null) {\n                startPatternIndex = index;\n            }\n            patternIndex += 1;\n        } else if (word[index] === word[index - 1]) {\n            continue;\n        } else {\n            patternIndex = 0;\n            startPatternIndex = null;\n            if (element === pattern[patternIndex] || element === pattern[patternIndex - 1]) {\n                startPatternIndex = index;\n                patternIndex += 1;\n            }\n        }\n    }\n    if (startPatternIndex !== null && patternIndex === 4) {\n        const size = index - startPatternIndex;\n        output = Math.max(output, size);\n    }\n    return output;\n};\n```
['JavaScript']