Simple JAVA Solution || Beats 100% || O(N)
Complexity\n- Time complexity: O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(N)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxChunksToSorted(int[] arr) {\n        int n = arr.length;\n        \n        // Initialize two arrays to store the maximum elements from the left side\n        // and the minimum elements from the right side for each index in the original array.\n        int maxleftarr[] = new int[n];\n        int minrightarr[] = new int[n];\n\n        // Calculate the maximum elements from the left side of the array.\n        maxleftarr[0] = arr[0];\n        for (int i = 1; i < n; i++) {\n            maxleftarr[i] = Math.max(maxleftarr[i - 1], arr[i]);\n        }\n\n        // Calculate the minimum elements from the right side of the array.\n        minrightarr[n - 1] = arr[n - 1];\n        for (int i = n - 2; i >= 0; i--) {\n            minrightarr[i] = Math.min(minrightarr[i + 1], arr[i]);\n        }\n\n        int ans = 0;// keep track of the number of chunks found so far.\n\n        // Compare the maximum element from the left side (maxleftarr[i]) with the minimum element\n        // from the right side (minrightarr[i+1]) for each index i in the array.\n        // If the maximum element from the left side is less than or equal to the minimum element\n        // from the right side for a given index, it means we can split the array into chunks at that index.\n        // Increment the ans variable to count the number of chunks.\n        for (int i = 0; i < n - 1; i++) {\n            if (maxleftarr[i] <= minrightarr[i + 1]) {\n                ans++;\n            }\n        }\n\n        // The ans variable will contain the number of chunks found, but we need to add 1 to get the final result,\n        // as the initial array itself is a chunk.\n        return ans + 1;\n    }\n}\n\n```
['Java']