Cody

# Problem 43072. Check if a rotated array was originally sorted

Solution 1599072

Submitted on 3 Aug 2018 by Anna Hughes
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = [4 5 6 7 0 1 2]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 0 1 2 4 5 6 7 index = 5 6 7 1 2 3 4 newx = 0 1 2 4 5 6 7

2   Pass
x = [2 5 6 8 0 1 3]; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 0 1 2 3 5 6 8 index = 5 6 1 7 2 3 4 newx = 0 1 3 2 5 6 8

3   Pass
x = [101, 103, 106, 109, 158, 164, 182, 187, 202, 205, 2, 3, 32, 57, 69, 74, 81, 99, 100]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205 index = 11 12 13 14 15 16 17 18 19 1 2 3 4 5 6 7 8 9 10 newx = 2 3 32 57 69 74 81 99 100 101 103 106 109 158 164 182 187 202 205

4   Pass
x = [42 1:10]; y_correct = true; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 1 2 3 4 5 6 7 8 9 10 42 index = 2 3 4 5 6 7 8 9 10 11 1 newx = 1 2 3 4 5 6 7 8 9 10 42

5   Pass
x = 1:10; x(1) = 100; x(4) = 1; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 1 2 3 5 6 7 8 9 10 100 index = 4 2 3 5 6 7 8 9 10 1 newx = 1 5 6 7 8 9 10 100 2 3

6   Pass
x = 10:-1:1; y_correct = false; assert(isequal(isRotaSorTED(x),y_correct))

sorted = 1 2 3 4 5 6 7 8 9 10 index = 10 9 8 7 6 5 4 3 2 1 newx = 1 10 9 8 7 6 5 4 3 2