Java simple 9 liner - no DP O(1) space; beats 96%
Intuition\nHave 2 variables l1 and l2 track the length of longest non-decreasing subarray ending at nums1 and nums2 respectively.\n\nAt each index i, we can upd
# Intuition\nHave 2 variables `l1` and `l2` track the length of longest non-decreasing subarray ending at `nums1` and `nums2` respectively.\n\nAt each index `i`, we can update `l1` as follows:\n- If `nums1[i-1] <= nums1[i]` then `l1 + 1`     \n- If `nums2[i-1] <= nums1[i]` then `l2 + 1`\n- else `1` (start a new subarray with `nums1[i]`)\n- Take max of all of above\n\nWe can do similar for `l2` and then track the max of `l1` and `l2` as the answer\n\n# Complexity\n- Time complexity: `O(n)`\n\n- Space complexity: `O(1)`\n\n# Code\n```\nimport static java.lang.Math.max;\n\nclass Solution {    \n    public int maxNonDecreasingLength(int[] nums1, int[] nums2) {        \n        int l1 = 1, l2 = 1, ans = 1;        \n        for(int i = 1; i < nums1.length; i++){\n            int t11 = nums1[i-1] <= nums1[i] ? l1 + 1 : 1;\n            int t12 = nums1[i-1] <= nums2[i] ? l1 + 1 : 1;\n            int t21 = nums2[i-1] <= nums1[i] ? l2 + 1 : 1;\n            int t22 = nums2[i-1] <= nums2[i] ? l2 + 1 : 1;\n            ans = max(ans, max(l1 = max(t11, t21), l2 = max(t12, t22)));\n        }\n        return ans;\n    }\n}\n```
['Java']