Source Code:https://thecodingsimplified.com/find-minimum-subarray-sorting-length/
Solution:
- We take two variable start = 0 & end = a.length - 1
- Now iterate start until you get increasing value & & decrease end until you get previous value is lesser than current value
- Once you get start & end, get max & min between start & end
- Now you keep on going from 'start' to 0th index & check if value is lesser than min then it'll be part of sorting
- Same way you check 'end' to last index that if value if lesser than max then this will be part of subarray.
- At last, you return end - start -1
Time Complexity: O(n)
Space Complexity: O(1)
CHECK OUT CODING SIMPLIFIED
https://www.youtube.com/codingsimplified
★☆★ VIEW THE BLOG POST: ★☆★
http://thecodingsimplified.com
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
https://www.youtube.com/codingsimplified?sub_confirmation=1
★☆★ Send us mail at: ★☆★
Email: [email protected]
Download
0 formats
No download links available.
Array - 40: Find Minimum subarray length such that If we sort this subarray, whole array be Sorted | NatokHD