3 ms·
I didin't really understand it either. I think the problem is taking in an array that's already been partitioned around a pivot, and then trying to figure out h
by jonathankoren 8y ago
I didin't really understand it either. I think the problem is taking in an array that's already been partitioned around a pivot, and then trying to figure out how many numbers could have been the pivot. The reason why this isn't just the length of the array is because the array is already pivoted. The reason why you have to use a linear scan is because the array is still in unsorted order.
For [1, 2, 3, 4, 5] there are 5 pivots.
For [1, 2, 3, 5, 4] there are 3 pivots (1, 2, and 3)
For [2, 1, 3, 5, 4] there is only 1 (3).
- monochromatic 8y agoThat makes more sense. Thanks.