Array - 40: Find Minimum subarray length such that If we sort this subarray, whole array be Sorted

preview_player
Показать описание
Solution:
- 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

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

great explanation! jst a little correction ig while finding max and min the start and end should be inclusive and at last it should return end-start+1 for subarray length

tilakrajrao
Автор

Very good explanation . Thanks alot . 👌🙂

rajulujyothi
Автор

Beautifully explained :)
Keep it up!
Jst a little correction i guess
in the discription u wrote the time complexity as O(n^2) instead of O(n)

tusharsrivastava
Автор

Real OG of the code GAME, , , keep making vedios sir #respect++

seraj_valley
Автор

In the last output should be end-start+1

It should be +1 and not -1 as the length

ajitbabu
Автор

Great explanation, keep up the good work.

faizanahmedkabuji