Simple java using NGE
\n\n# Code\n\nclass Solution {\n    public int maxChunksToSorted(int[] arr) {\n        Stack<Integer> a= new Stack<Integer>();\n\n        for(int i=0;i<arr.leng
\n\n# Code\n```\nclass Solution {\n    public int maxChunksToSorted(int[] arr) {\n        Stack<Integer> a= new Stack<Integer>();\n\n        for(int i=0;i<arr.length;i++)\n        {\n                int mx=arr[i];\n            while(!a.isEmpty()&&arr[i]<a.peek())\n            {\n                mx= Math.max(mx,a.peek());\n                a.pop();\n            }\n\n            a.push(mx);\n        }\n        return(a.size());\n    }\n}\n```
['Java']