![]() |
VOOZH | about |
Given an array arr[]. The task is to divide arr[] into the maximum number of partitions, such that, those partitions if sorted individually make the whole array sorted.
Examples:
Input: arr[] = { 28, 9, 18, 32, 60, 50, 75, 70 }
Output: 4
Explanation: Following are the partitions in which the array is divided.
If we divide arr[] into four partitions {28, 9, 18}, {32}, { 60, 50}, and {75, 70}, sort them and concatenate.
Sorting all of them indivudually makes the whole array sorted.
Hence, 4 is the answer.Input: arr[] = { 2, 1, 0, 3, 4, 5 }
Output: 4
Approach: This problem is implementation-based. Follow the steps below to solve the given problem.
Below is the implementation of the above approach.
4
Time Complexity: O(N)
Auxiliary Space: O(N)