Straightforward Sliding Window Solution Without DP
keep track the left window index. if there is a break, then take the index for new window.\n# Code\n\nclass Solution {\npublic:\n    int maxNonDecreasingLength(
keep track the left window index. if there is a break, then take the index for new window.\n# Code\n```\nclass Solution {\npublic:\n    int maxNonDecreasingLength(vector<int>& nums1, vector<int>& nums2) {\n        // j: start index of the window\n        // i : end index of the window\n        // mxed: index of first time taked the maxed value\n        // pre: previous value of the window, if window.size = 0, then pre = 0\n        int n = nums1.size(), ans = 0, pre = 0, j = 0, mxed = -1; \n        for (int i = 0; i < n; ++i) {\n            int cur = -1, mn = min(nums1[i], nums2[i]), mx = max(nums1[i], nums2[i]);\n            if (mn >= pre) {\n                cur = mn;\n            } else if (mx >= pre) {\n                if (mxed == -1) {\n                    mxed = i;\n                }\n                cur = mx;\n            } else {\n                if (mxed != -1) {\n                    i = mxed - 1;\n                    mxed = -1;\n                } else {\n                    i--;\n                }\n                pre = 0, j = i + 1;\n            }\n            if (cur != -1) {\n                pre = cur;\n                ans = max(ans, i - j + 1);\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']