Fast Java Solution
Intuition\nI will consider the vowels as stages with their alphabetical order and make sure no stages have been skipped and we have passed by all stages to find
# Intuition\nI will consider the vowels as stages with their alphabetical order and make sure no stages have been skipped and we have passed by all stages to find the complete substring\n# Approach\nApproach is described within the comments\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    public int longestBeautifulSubstring(String word) {\n        int maxLength = 0;\n        // edge case\n        if (word.length() < 5) {\n            return maxLength;\n        }\n        int startLocation = 0;\n        int currentStage = 0;\n        int vowelStage = 0;\n        boolean sequenceStarted = false;\n        // main for loop on all characters\n        for (int i = 0; i < word.length(); i++) {\n            char c = word.charAt(i);\n            vowelStage = getStage(c);\n            // starting our sequence\n            if (!sequenceStarted && vowelStage == 1) {\n                currentStage = 1;\n                sequenceStarted = true;\n                startLocation = i;\n            }\n            // ending the sequence\n            else if (sequenceStarted && vowelStage < currentStage) {\n                sequenceStarted = false;\n                currentStage = 0;\n                // we may restart the sequence if we meet an \'a\'\n                if (vowelStage == 1) {\n                    i--;\n                }\n            } else if (sequenceStarted && vowelStage >= currentStage) {\n                // in middle of sequence\n                if (currentStage == 5) {\n                    // expanding the complete substring\n                    if (vowelStage == 5) {\n                        if (((i - startLocation + 1)) > maxLength) {\n                            maxLength = i - startLocation + 1;\n                        }\n                    } else {\n                        // sequence ended by a stage less than 5\n                        sequenceStarted = false;\n                        currentStage = 0;\n                        // restart sequence possible\n                        if (vowelStage == 1) {\n                            i--;\n                        }\n                    }\n                } else {\n                    // upgrading stage\n                    if (vowelStage == (currentStage + 1)) {\n                        currentStage = vowelStage;\n                        if (vowelStage == 5) {\n                            if (((i - startLocation) + 1) > maxLength) {\n                                maxLength = i - startLocation + 1;\n                            }\n                        }\n                        // found the same stage still present\n                    } else if (vowelStage == currentStage) {\n                        continue;\n                    } else {\n                        // a stage has been skipped\n                        sequenceStarted = false;\n                        currentStage = 0;\n                    }\n                }\n            }\n        }\n        return maxLength;\n    }\n\n    private int getStage(char c) {\n        int stage;\n        switch (c) {\n            case \'a\':\n                stage = 1;\n                break;\n            case \'e\':\n                stage = 2;\n                break;\n            case \'i\':\n                stage = 3;\n                break;\n            case \'o\':\n                stage = 4;\n                break;\n            case \'u\':\n                stage = 5;\n                break;\n            default:\n                stage = 0;\n        }\n        return stage;\n    }\n}\n```
['String', 'Sliding Window', 'Java']