dev-masih
dev-masih

Reputation: 4756

How sorting parts of array my cause the whole array to be sorted

Recently i come across this problem and i couldn't find a solution for it, the problem is there is a array of numbers (N number) and we want to sort them, but we sort them in the way that shows in the picture:

image

First Sort from 1 to K+L  
then Sort from K+1 to N  
then Sort from 1 to K+L again. 

that means from K+1 to K+L will sort twice.
The question is what is L should be to whole array be sorted?

Upvotes: 0

Views: 27

Answers (1)

timrau
timrau

Reputation: 23058

When L = N - K, the whole array could be sorted.

Upvotes: 1

Related Questions